如何使用python缩放数据以显示时间序列图?

时间:2020-06-10 14:29:49

标签: python python-3.x pandas time-series data-visualization

我进行了可视化。它以GB为单位显示许多类型的文件的大小。我可以用什么来缩放它? 在图中,我只能看到3个“ file_name”。但是传说中的单桅三角帆船不止3艘。

import pandas as pd

df = pd.DataFrame({
    'file_type': ['file'] * 1 +  ['file.png'] * 1 +  ['file.PNG'] * 1 + ['file.csv'] * 2,
    'size': [11] * 5,
    'created_at': ['2020-01-01 23:00:34'] *1 + ['2020-02-01 23:00:34'] * 2 + ['2020-03-01 23:00:34']*1 + ['2019-01-02 23:00:34']})

df['created_at'] = pd.to_datetime(df['created_at']).dt.normalize()
group1= df['file_type'].str.lower().str.extract(r'(\.\w+$)', expand=False).fillna('unknown')
group2 = df['created_at'].dt.strftime('%Y-%m')

df_new=df.groupby([group1, group2])['size'].sum().div(1000000000).round(3).unstack(level=0)
df_new.plot(subplots=False, figsize=(10, 8))

enter image description here

编辑 我添加了给出的建议。情节现在看起来像这样:

enter image description here

0 个答案:

没有答案