在导入时指定dtype选项或将low_memory = False设置为

时间:2018-12-12 20:22:57

标签: python pandas dataframe

我正在使用以下代码:

df = pd.read_csv('/Python Test/AcquirerRussell3000.csv')

我有以下类型的数据:

18.07.2000  27.1875         0 08.08.2000  25.3125       0.1 05.09.2000  \
0   19.07.00  26.6250 -0.020690   09.08.00  25.2344 -0.003085   06.09.00   
1   20.07.00  26.6250  0.000000   10.08.00  25.1406 -0.003717   07.09.00   
2   21.07.00  25.6875 -0.035211   11.08.00  25.5781  0.017402   08.09.00   
3   24.07.00  26.2500  0.021898   14.08.00  25.4375 -0.005497   11.09.00   
4   25.07.00  26.6875  0.016667   15.08.00  25.5625  0.004914   12.09.00 

我遇到以下错误:

Pythone Test/untitled0.py:1: DtypeWarning: Columns (long list of numbers) have mixed types. 
Specify dtype option on import or set low_memory=False.

因此,每个第三列都是一个日期,其余均为数字。我猜没有单一的dtype,因为日期是字符串,其余的是float或int?我有大约5000列或更多,大约400行。

我已经看到与此类似的问题,但还不太了解如何将其应用于我的数据。此外,我想在堆栈数据帧之后运行以下代码。

a = np.arange(len(df.columns))
df.columns = [a % 3, a // 3]
df = df.stack().reset_index(drop=True)

df.to_csv('AcquirerRussell3000stacked.csv', sep=',')

我应该使用什么dtype?还是应该将low_memory设置为false?

1 个答案:

答案 0 :(得分:0)

这从here

解决了我的问题
dashboard_df = pd.read_csv(p_file, sep=',', error_bad_lines=False, index_col=False, dtype='unicode')

有人能向我解释这个答案吗?