我尝试了多种方法将日期从最早排序到当前,但我无法做到这一点。我想这一定是我忽略了的一些简单的事情,所以我伸出援助之手
对于matplotlib、python和python,我还是新手。我真的很感谢这个社区对我的帮助
我已将日期超时分为月份和年份,以便为期间创建一列。我正在寻找排序的总节省每个时期从最早到最新的
ausers["period"] = ausers['year'].astype(str)+' '+ ausers['month'].astype(str)
atime = ausers.period.value_counts()
atime.plot(kind='bar')
plt.title('Successful saves by month')
plt.ylabel('Number of saves')
plt.xlabel('month')
目前,我有图表,因为它需要看,但我不能让它排序的保存数量按时期
我在想也许我需要重新安排我的月经,这样我就有了第一个月
因此,为了对与日期相关的任何内容进行排序,我将首先维护“date”数据类型以获得正确的排序
将原始列转换为datetime(在您将其拆分为年/月列之前)
import pandas as pd ausers["Period"] = pd.to_datetime(ausers['original_date_col'], format='%Y:%m')
'Period'
添加到df中,并将date_col
转换为datetime以便于排序李>'%Y-%m'
,输出将类似于2019-08
然后对df进行排序:
ausers = ausers.sort_values(['Period'])
希望这有助于/提供价值:)
相关问题 更多 >
编程相关推荐