记录 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

 

5.conn = pymysql.connect(host = 'localhost', user = 'root', password = '123456', port = '3306', db = 'mysql')

出错:TypeError: %d format: a number is required, not str

原因:port = '3306',写错了,应该去掉引号。正确写法:port = 3306

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值