dtype에서 여러 열의 s 를 설정하고 싶습니다 pd.Dataframe(파일이 수정되지 않았기 때문에 목록 목록으로 수동으로 구문 분석해야하는 파일이 있습니다 pd.read_csv).
import pandas as pd
print pd.DataFrame([['a','1'],['b','2']],
dtype={'x':'object','y':'int'},
columns=['x','y'])
나는 얻다
ValueError: entry not a 2- or 3- tuple
내가 설정할 수있는 유일한 방법은 각 열 변수를 반복하고 astype.
dtypes = {'x':'object','y':'int'}
mydata = pd.DataFrame([['a','1'],['b','2']],
columns=['x','y'])
for c in mydata.columns:
mydata[c] = mydata[c].astype(dtypes[c])
print mydata['y'].dtype #=> int64
더 좋은 방법이 있습니까?
df = pd.DataFrame([['a','1'],['b','2']], dtype='int', columns=['x','y'])"작품":하지만 ...의