可能是一个非常简单的修复,但我的英语不够好,无法找到正确的答案。
Python / Pandas正在改变我正在编写的数字:6570631401430749,类似于:6.17063140131e + 15
我正在合并数百个csv文件,这一列出错了。列的名称是“serialnumber”,它是第3列。
import pandas as pd
import glob
import os
interesting_files = glob.glob("*.csv")
df_list = []
for filename in sorted(interesting_files):
frame = pd.read_csv(filename)
print(os.path.basename(filename))
frame['filename'] = os.path.basename(filename)
df_list.append(frame)
full_df = pd.concat(df_list)
full_df.to_csv('output.csv',encoding='utf-8-sig')
答案 0 :(得分:2)
如果要以原始格式保留数据,则可以在阅读csv时使用dtype = object
。您可以将代码更改为
import pandas as pd
import glob
import os
interesting_files = glob.glob("*.csv")
df_list = []
for filename in sorted(interesting_files):
frame = pd.read_csv(filename,dtype=object)
print(os.path.basename(filename))
frame['filename'] = os.path.basename(filename)
df_list.append(frame)
full_df = pd.concat(df_list)
full_df.to_csv('output.csv',encoding='utf-8-sig')