【发布时间】:2017-05-24 13:11:25
【问题描述】:
我正在尝试读取包含科学计数法数字列的 .csv。 无论我做什么,最终都会将它们读取为字符串:
def readData(path, cols):
types = [str, str, str, str, np.float32]
t_dict = {key: value for (key, value) in zip(c, types)}
df = pd.read_csv(path, header=0, sep=';', encoding='latin1', usecols=cols, dtype=t_dict, chunksize=5000)
return df
c = [3, 6, 7, 9, 16]
df2017_chunks = readData('Data/2017.csv', c)
def preProcess(df, f):
df.columns = f
df['id_client'] = df['id_client'].apply(lambda x: str(int(float(x))))
return df
f = ['issue_date', 'channel', 'product', 'issue', 'id_client']
df = pd.DataFrame(columns=f)
for chunk in df2017_chunks:
aux = preProcess(chunk, f)
df = pd.concat([df, aux])
如何正确读取这些数据?
【问题讨论】:
-
你能从 CSV 文件中发布一个 pandas 试图读取的小样本吗?
标签: python csv pandas scientific-notation