Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

Python用データ分析ライブラリPandaをつかう その2:CSVのデータをつっこむ

import pandas as pd
import numpy as np

csv = pd.read_csv('sample.csv')
print(csv)
#  county  precinct     office  district party       candidate  votes
#0  Clark         1  President       NaN   REP  John R. Kasich      5
#1  Clark         2  President       NaN   REP  John R. Kasich      0
#2  Clark         3  President       NaN   REP  John R. Kasich      7

print(csv.index)
#RangeIndex(start=0, stop=3, step=1)

print(csv.columns)
#Index(['county', 'precinct', 'office', 'district', 'party', 'candidate',
#       'votes'],
#      dtype='object')

print(csv.values)
#[['Clark' 1 'President' nan 'REP' 'John R. Kasich' 5]
# ['Clark' 2 'President' nan 'REP' 'John R. Kasich' 0]
# ['Clark' 3 'President' nan 'REP' 'John R. Kasich' 7]]