03_create_data_frame
In [1]:
import pandas as pd
In [2]:
s = pd.Series(["bonggu", 31])
print(s)
0    bonggu
1        31
dtype: object


Series 생성

In [3]:
s = pd.Series(["bong_gu", "chatterBOX"])
s = pd.Series(["bong_gu", "cahtterBOX"], index=["person", "who"])
print(s)
person       bong_gu
who       cahtterBOX
dtype: object


DataFrame 생성

  • dictionary
In [4]:
scientists = pd.DataFrame({
    'Name': ["Bong_gu", "Yang_o"],
    "Job" : ["buyer", "Data_analysis"],
    "Born": ["SEOUL", "DONGHAE"],
    "Age": [31, 31],
    "Hate": ["JaeHyeop","JAeHyeop"]
}, index=["Bong_gu", "Yang_o"], columns=["Name", "Job", "Born", "Hate", "Age"] )
scientists
Out[4]:
Name Job Born Hate Age
Bong_gu Bong_gu buyer SEOUL JaeHyeop 31
Yang_o Yang_o Data_analysis DONGHAE JAeHyeop 31
In [5]:
## DataFrame에서 순서보장
from collections import OrderedDict

scientists = pd.DataFrame(OrderedDict([
    ["name", ["Rosaline Franklin", "William Gosset"]],
    ["Occupation", ["Chemist", "Statistician"]],
    ["Born", ["1920-07-25", "1876-06-13"]],
    ["Died", ["1958-04-16", "1937-10-16"]],
    ["Age", [37, 61]]
]))

print(scientists)
                name    Occupation        Born        Died  Age
0  Rosaline Franklin       Chemist  1920-07-25  1958-04-16   37
1     William Gosset  Statistician  1876-06-13  1937-10-16   61
In [6]:
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
02.basic_statistic  (0) 2018.12.09
01.data_slicing  (0) 2018.12.09

+ Recent posts