记录 python 编程中遇到的错误

1. 记录一个粗心大意导致的错误:'DataFrame' object has no attribute 'piovt'

原因是拼写错误,正确的应该是 pivot

df.pivot('A','B','C')

要注意细节

2.index=pd.date_range('11/13/2018',period=1000)

出错: TypeError: __new__() got an unexpected keyword argument 'period'

看了pandas 0.23.4 documentation 网址 http://pandas.pydata.org/pandas-docs/stable/generated/pandas.date_range.html之后,把period改为periods好了。

3.index=pd.Datetimeindex(['11/12/2018','11/22/2018‘])

出错 AttributeError: module 'pandas' has no attribute 'Datetimeindex'

把 'Datetimeindex'中的index的i改为大写I

4.D=Series([0,1,2,3,4,5,6,7,8,9])

pd.rolling_sum(D,2)

出错:AttributeError: module 'pandas' has no attribute 'rolling_sum'

python版本3.7. 正确写法:D.rolling(2).sum()

In[1]: D.rolling(2).sum()
Out[1]: 
0     NaN
1     1.0
2     3.0
3     5.0
4     7.0
5     9.0
6    11.0
7    13.0
8    15.0
9    17.0
dtype: float64

猜你喜欢

转载自blog.csdn.net/dlwsd_/article/details/83963574
今日推荐