简体   繁体   English

在短时间内绘制时间序列数据的最佳方法

[英]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_dateSales求和。

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.

相关问题 matplotlib:在时间序列中的期间数据下居中期间标签 plot - matplotlib: Centering period labels under the period's data in a time-series plot 如何更有效地生成时间序列 SQL 数据的每个时间段的绘图行数? - How to generate plot row count per time period of time series SQL data in plotly more efficiently? 试图创建一个时间数据系列,但情节是错误的 - Trying to create a time-data series but plot is wrong way round 在时间序列中查找时间段 - Find period in a Time Series 实施试用期或到期时间的最佳方法 - Best way to implement trial period or expire time 为时间序列数据创建flink表的最佳方式是什么 - What's the best way to create flink table for time series data 从熊猫的时间序列数据中删除插值的最佳方法是什么? - What is the best way to remove interpolation from a time series data in Pandas? 使用 Python 填充时间序列中缺失数据的最佳方法是什么? - Whats the best way to fill the missing data in the time series using Python? 如何在短时间内禁用“系统”服务或进程? 蟒蛇 - Way to disable “System” service or process for a short period of time? Python xarray - 按任意时间段重新采样时间序列数据 - xarray - Resample time-series data by arbitrary time period
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM