gpt4 book ai didi

python - 带有值图、Pandas 和 MatPlotLib 的月、年

转载 作者:行者123 更新时间:2023-12-03 23:29:11 24 4
gpt4 key购买 nike

我有带月、年和值的 DataFrame,我想做一个时间序列图。

样本:

month   year    Value
12 2016 0.006437804129357764
1 2017 0.013850880792606646
2 2017 0.013330349031207292
3 2017 0.07663058273768052
4 2017 0.7822831457266424
5 2017 0.8089573099244689
6 2017 1.1634845000200715

我试图用 X 轴中的年和月、年和月以及 Y 轴中的值来绘制此值数据。

最佳答案

一种方法是这样的:

import pandas as pd
import matplotlib.pyplot as plt

df['date'] = df['month'].map(str)+ '-' +df['year'].map(str)
df['date'] = pd.to_datetime(df['date'], format='%m-%Y').dt.strftime('%m-%Y')
fig, ax = plt.subplots()
plt.plot_date(df['date'], df['Value'])
plt.show()

enter image description here

关于python - 带有值图、Pandas 和 MatPlotLib 的月、年,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53259415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com