我想为一个dataframe列构造一个直方图(或经验分布函数)(=一个包含一些日常观察的列)。dataframe列有以下结构(下面),谢谢!
df1 = pd.DataFrame({"date": pd.to_datetime(["2021-3-22", "2021-4-7", "2021-4-18", "2021-5-12","2022-3-22", "2022-4-7", "2022-4-18", "2022-5-12"]),
"x": [1, 1, 1, 3, 2, 3,4,2 ]})
date x
0 2021-03-22 1
1 2021-04-07 1
2 2021-04-18 1
3 2021-05-12 3
4 2022-03-22 2
5 2022-04-07 3
6 2022-04-18 4
7 2022-05-12 2发布于 2022-08-02 19:57:53
熊猫具有默认的matplotlib后端绘图功能,因此您可以这样做:
df1.x.hist()更多:https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.html
发布于 2022-08-02 19:48:37
你可以用pyplot来完成这个任务:
from matplotlib import pyplot as plt
plt.hist(df1.x)
#if you just want to look at the plot
plt.show()
#if you want to save the plot to a file
plt.savefig('filename.png')下面是包含所有选项的文档:https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html。
https://stackoverflow.com/questions/73212907
复制相似问题