AttributeError: 'Timestamp' object has no attribute 'weekday_name

  • 运行这段代码时,出现报错,这段代码是取出Timestamp中的星期几
week = pd.DatetimeIndex(data['place_order_time'])
data['weekday'] = week.weekday_name()
  • 报错为AttributeError: 'Timestamp' object has no attribute 'weekday_name'
    是因为weekday_name已经被day_name函数替换了
  • 解决办法:将weekday_name替换成day_name

pandas.errors.InvalidIndexError: (slice(None, None, None), None)

  • 运行下面这段代码时,出现报错
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 7))   # 设置绘图窗口
plt.rcParams['font.sans-serif'] = 'SimHei'    # 中文字体
plt.scatter(range(1, 32), number, marker='D')
plt.plot(range(1, 32), number)
plt.title('2016年8月餐饮销售额趋势示意图')
plt.xlabel('日期')
plt.ylabel('销售额')
plt.xticks(range(0, 32)[::7], range(0, 32)[::7])
# plt.show()
  • 报错为pandas.errors.InvalidIndexError: (slice(None, None, None), None)'
    是因为number有两列,两列是不能作为值的,所以我们要加上我们要选取的两列中其中一列的值
  • 解决办法:将代码改为plt.plot(range(1, 32), number['price'])
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐