【问题标题】:Line Plot in MathPlotLib, by frequency of dateMatPlotLib 中的线图,按日期频率
【发布时间】:2019-03-13 19:02:10
【问题描述】:

所以我在 pandas 中有一个如下所示的数据框:

    date         max     min    rain    snow    ice
0   2019-01-01   58      39     0.06    0.0     0.0
1   2019-01-01   58      39     0.06    0.0     0.0
2   2019-01-01   58      39     0.06    0.0     0.0
3   2019-01-01   58      39     0.06    0.0     0.0
4   2019-01-01   58      39     0.06    0.0     0.0

目标是创建一个线图,在 x 轴上显示最高温度,在 y 轴上显示该温度下每个日期的频率。

所以基本上,日期列表是商店交易,我想看看温度对每天交易数量的影响。

我尝试使用它来按日期对 weather_frame 进行分组,但我无法让我的绘图显示 x 轴上的温度。

max_temp = weather_frame.groupby(weather_frame.date).size()

我已附上以下文件。我不得不删除其中一些以保持在粘贴箱的大小限制内,因此,图表可能会出现损坏。 Data Link

【问题讨论】:

    标签: python visualization


    【解决方案1】:
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    date_freq = weather_frame.groupby(weather_frame.date).size()
    max_temp = weather_frame[['date', 'max']].groupby(weather_frame.date).mean()
    
    sns.set()
    plt.figure()
    sns.regplot(x=max_temp, y=date_freq)
    plt.xlabel('Maximum Temperature')
    plt.ylabel('Number of Transactions per Day')
    

    看起来最高温度和每天的交易数量之间存在轻微的正相关关系。

    【讨论】:

      猜你喜欢
      • 2018-03-13
      • 2020-10-01
      • 1970-01-01
      • 2021-09-25
      • 2016-08-06
      • 2018-01-24
      • 2016-12-05
      • 2020-09-22
      相关资源
      最近更新 更多