Python/Pandas
[Python] 데이터프레임 만들기 :: pd.DataFrame()
뭬자
2019. 11. 26. 18:17
Import Pandas
import pandas as pd
Dataframe 생성
pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
1.
student_card = pd.DataFrame({'ID':[20190103, 20190222, 20190531],
'name':['Kim', 'Lee', 'Jeong'],
'class':['H', 'W', 'S']})
student_card
2.
student_card = pd.DataFrame([[20190103, 'Kim', 'H'],
[20190222, 'Lee', 'W'],
[20190531, 'Jeong', 'S']], columns = ['ID', 'name', 'class'])
student_card
+ 인덱스 지정
student_card = pd.DataFrame({'ID':[20190103, 20190222, 20190531],
'name':['Kim', 'Lee', 'Jeong'],
'class':['H', 'W', 'S']}, index = ['a', 'b', 'c']) #index 지정
student_card
+ 데이터 타입 지정
dtype 옵션으로 데이터 타입을 지정할 수 있다.
student_card = pd.DataFrame([[1, 2, 3], [4, 5, 6]],
columns = ['a', 'b', 'c'], dtype = float) #data type 지정
student_card
반응형