【问题标题】:How to set conditions for plotting values from a 3rd column? Python/pandas如何设置从第三列绘制值的条件?蟒蛇/熊猫
【发布时间】:2020-01-26 17:58:07
【问题描述】:

我已将 pandas 的数据导入 3 列:DayOfYear、Field、Distance。

DayOfYear Field Distance
1          50      100
2          55      200
3          60      300
4          65      400
5          70      500
6          75      600
7          80      700
...          

我想针对距离绘制场,但我想在一年中选择的任何日期范围内进行绘制。 因此,不仅仅是绘制所有 365 天的距离和场的所有值, 我想将它们绘制在第 226-346 天。我该怎么办?

【问题讨论】:

    标签: python pandas plot


    【解决方案1】:

    使用Series.between 执行boolean indexingDataFrame.plot

    l1 = 226
    l2 = 346
    df[df['DayOfYear'].between(l1,l2)].set_index('Distance')['Field'].plot()
    

    示例 l1 = 2, l2 = 6,

    【讨论】:

    • pandas.pydata.org/pandas-docs/stable/reference/api/… , DataFrame.plot 使用 DataFrame 在 x 轴的索引,所以我们需要像`index`一样设置distance。请考虑接受或投票:)
    • 您需要使用我们使用的日期时间序列按小时过滤数据帧s.dt.hour.between(3,4)
    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2016-10-16
    • 2021-11-09
    • 2018-01-16
    • 2022-01-11
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    相关资源
    最近更新 更多