[英]The best way to plot time series data for a short period of time
I have a dataset with two columns "new_date" and "Sales".我有一个包含两列“new_date”和“Sales”的数据集。 The dataset captures the daily sales for a company over 3 months in just one year 2020, "ie, Jan, Feb, and March".该数据集捕获了一家公司在 2020 年仅一年(即 1 月、2 月和 3 月)中 3 个月以上的每日销售额。 The size of the dataset is about 8000 rows.数据集的大小约为 8000 行。 One day might have different transaction or different sales.一天可能有不同的交易或不同的销售。
new_date Sales
2020-01-26 453
2020-01-26 232
2020-02-03 123
2020-02-03 223
2020-03-13 333
2020-03-23 657
My question is that is it possible to plot the time series for this short period date?我的问题是,是否可以绘制这个短期日期的时间序列? And what is the best choice.什么是最好的选择。
I simply tried to use plot我只是尝试使用情节
df.plot(legend=False)
But the results is not as good as I was expect.但是结果并没有我想象的那么好。
Is there any better way to visualize and organize this time series data?有没有更好的方法来可视化和组织这个时间序列数据?
I'm not sure what you are exactly looking for, but based on the data I guess you could sum the Sales
first by new_date
.我不确定您到底在寻找什么,但根据数据,我猜您可以new_date
对Sales
求和。
df.groupby('new_date').sum().plot(legend=False)
When you want to sum Sales
per week, you can use resample
:当您想对每周的Sales
求和时,可以使用resample
:
import pandas as pd
import random
df = pd.DataFrame({
'new_date' : pd.date_range('2022-01-01', '2022-03-31'),
'Sales' : random.sample(range(100, 1000), 90)}).set_index('new_date')
df.resample('W').sum().plot(legend=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.