我的数据框看起来像 - can sbi bjf srt acc amb tata jsw hdfcl sbilDate 2018-02-07 248.65 259.10 2298.40 1284.65 1313.75 200.30 560.95 313.25 457.65 667.902018-03-07 244.70 257.75 2321.50 1298.45 1336.80 200.85 566.50 311.80 459.65 669.902018-04-07 244.75 257.50 2331.95 1144.85 1352.65 201.15 568.90 312.00 459.60 664.602018-05-07 243.75 256.60 2329.45 1151.90 1388.95 207.30 553.50 310.40 462.05 663.152018-06-07 247.80 257.45 2341.70 1110.55 1373.45 207.35 554.15 309.30 468.90 667.402018-09-07 249.55 261.35 2346.60 1139.95 1375.90 206.40 556.85 312.95 474.30 664.902018-10-07 250.75 263.50 2366.30 1206.35 1371.50 204.10 568.60 316.75 476.70 660.002018-11-07 244.15 258.90 2355.20 1205.80 1360.70 202.45 555.85 312.65 469.05 660.952018-12-07 241.40 262.75 2414.30 1214.00 1349.15 202.05 556.30 316.80 478.00 664.352018-07-13 231.95 257.60 2460.35 1253.55 1335.95 197.15 558.15 316.75 471.70 660.45我想根据这个数据框做一些EDA。我的代码如下 -import numpy as npimport pandas as pd# import pandas_datareader.data as webimport matplotlib.pyplot as pltimport statsmodels.regression.linear_model as rgimport arch.unitroot as atimport mxnet as mxdata = pd.read_csv('/Users/XXXX/Downloads/Pairs-Trading-Analysis-Data.csv', index_col='Date', parse_dates=True)data.head(10)int1 = data.loc[:, ['bjf', 'srt']]tint1 = int1[:'2018-12-31']tint1.columns = ['taus', 'tcan']fint1 = int1['2019-01-02':]fint1.columns = ['faus', 'fcan']但最主要的是,当我使用 Windows 时,我没有收到任何错误,但当我使用 MAC 操作系统时,就会出现此错误。有什么具体原因吗?如何纠正这个错误?
1 回答
jeck猫
TA贡献1909条经验 获得超7个赞
我遇到了类似的问题,我的解决方案是:
确保索引是“DatetimeIndex”类型,我这样做:
df.index = pd.to_datetime(df.index)
首先对'索引'进行排序:
df = df.sort_index()
然后操作(如下)应该可以工作:
df_sub = df['2018'] # select the whole year of 2018
df_sub2 = df['2018-02'] # select the given month
df_sub3 = df['2018-01':'2018-03'] # select between dates
添加回答
举报
0/150
提交
取消