In [1]:
import pandas as pd
from collections import OrderedDict
In [2]:
scientists = pd.read_csv("./data/scientists.csv")
열의 자료형 바꾸기와 새로운 열 추가¶
In [3]:
print("Born type: {}".format(scientists["Born"].dtype))
print("Died type: {}".format(scientists["Died"].dtype))
In [4]:
born_datetime = pd.to_datetime(scientists["Born"], format="%Y-%m-%d")
print("born_datetime: \n{}".format(born_datetime))
print("\n===================================\n")
died_datetime = pd.to_datetime(scientists["Died"], format="%Y-%m-%d")
print("died_datetime: \n{}".format(died_datetime))
In [5]:
scientists["born_dt"], scientists["died_dt"] = [born_datetime, died_datetime]
scientists.head()
Out[5]:
In [6]:
scientists["age_days"] = (scientists["died_dt"] - scientists["born_dt"])
scientists.head()
Out[6]:
In [7]:
import random
print(scientists["Age"])
print("\n===================================\n")
random.seed(42)
random.shuffle(scientists["Age"])
print(scientists["Age"])
열 삭제¶
In [8]:
print(scientists.columns)
print("\n===================================\n")
scientists_dropped = scientists.drop(["Age"], axis=1)
print(scientists_dropped.columns)
In [9]:
from IPython.core.display import display, HTML
display(HTML("<style> .container{width:100% !important;}</style>"))
'pandas > basic' 카테고리의 다른 글
06.handling_dataframe(bool) (0) | 2018.12.09 |
---|---|
05.handling_series(apply) (0) | 2018.12.09 |
04.handling_series(basic) (0) | 2018.12.09 |
03.create_data_frame (0) | 2018.12.09 |
02.basic_statistic (0) | 2018.12.09 |