gpt4 book ai didi

python - pandas 星期几轴标签

转载 作者:行者123 更新时间:2023-12-03 01:01:58 34 4
gpt4 key购买 nike

我正在策划一个为期一周的 Pandas 系列。我的代码:

rng = pd.date_range('1/6/2014',periods=169,freq='H')
graph = pd.Series(shared_index, index=rng[:168])
graph.plot(shared_index)

显示 7 个 x 轴标签:

[06 Jan 2014, 07, 08, 09, 10, 11, 12]

但我想要:

[Mon, Tue, Wed, Thu, Fri, Sat, Sun]

我应该在代码中指定什么来更改轴标签?

谢谢!

最佳答案

也许您可以手动修复刻度标签:

rng = pd.date_range('1/6/2014',periods=169,freq='H')
graph = pd.Series(np.random.randn(168), index=rng[:168])
ax = graph.plot()

weekday_map= {0:'MON', 1:'TUE', 2:'WED', 3:'THU',
4:'FRI', 5:'SAT', 6:'SUN'}

xs = sorted(ax.get_xticks(minor='both'))
wd = graph.index[xs - xs[0]].map(pd.Timestamp.weekday)

ax.set_xticks(xs)
ax.set_xticks([], minor=True)
ax.set_xticklabels([weekday_map[d] for d in wd])

week-day

关于python - pandas 星期几轴标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22536179/

34 4 0