Pandas 绘制数据帧时,如何设置';YYYY-MM';价值
我有一个具有以下值的参数。我可以创建一个漂亮的图表,如下所示:Pandas 绘制数据帧时,如何设置';YYYY-MM';价值,pandas,plot,Pandas,Plot,我有一个具有以下值的参数。我可以创建一个漂亮的图表,如下所示: import matplotlib.pyplot as plt ax = pdf_month.plot(x="month", y="count", kind="bar") plt.show() 我想截断日期范围(忽略1900-01-01和其他不导入的月份,但每次尝试时都会收到错误消息(见下文)。日期范围类似于“2016-01”到“2018-04” ax.set\u xlim(pdf\u month['month'][17],p
import matplotlib.pyplot as plt
ax = pdf_month.plot(x="month", y="count", kind="bar")
plt.show()
我想截断日期范围(忽略1900-01-01和其他不导入的月份,但每次尝试时都会收到错误消息(见下文)。日期范围类似于“2016-01”到“2018-04”ax.set\u xlim(pdf\u month['month'][17],pdf\u date['count'].values.max())
其中,pdf\u month['month'][17]
给出的值为u'2017-01'
pdf_month.printSchema
root
|-- month: string (nullable = true)
|-- count: long (nullable = false)
如何为不是整数或日期的x值设置月份值的范围。我仍然有原始的、预先分组的日期。是否有更好的方法按月份分组以允许您自定义x轴
错误消息:
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
pd_月的样本输出
month count
0 1900-01 353
1 2015-09 1
2 2015-10 2
3 2015-11 2
4 2015-12 1
5 2016-01 1
6 2016-02 1
7 2016-03 3
8 2016-04 2
9 2016-05 5
10 2016-06 7
11 2016-07 13
12 2016-08 12
13 2016-09 41
14 2016-10 19
15 2016-11 17
16 2016-12 20
您可以尝试序列日期索引,熊猫系列允许按如下方式进行日期切片:
df.month['2016-01': '2018-04']
这适用于日期时间索引