【问题标题】:Plot the graph excluding missing values in pandas or matplotlib绘制不包括 pandas 或 matplotlib 中缺失值的图形
【发布时间】:2018-06-01 14:05:30
【问题描述】:

我是使用 Pandas 进行时间序列编程的新手。 这是示例数据:

                     date       2      3      4  ShiftedPrice
0 2017-11-05 09:20:01.134  2123.0  12.23  34.12         300.0
1 2017-11-05 09:20:01.789  2133.0  32.43  45.62         330.0
2 2017-11-05 09:20:02.238  2423.0  35.43  55.62           NaN
3 2017-11-05 09:20:02.567  3423.0  65.43  56.62           NaN
4 2017-11-05 09:20:02.948  2463.0  45.43  58.62           NaN

我想为 ShiftedPrice 列没有缺失值的所有对绘制日期与 ShiftedPrice 的关系。您可以假设数据列中绝对没有缺失值。所以请帮帮我。

【问题讨论】:

    标签: python pandas matplotlib time-series


    【解决方案1】:

    您可以先将NaNs 行删除dropna:

    df = df.dropna(subset=['ShiftedPrice'])
    

    然后plot:

    df.plot(x='date', y='ShiftedPrice')
    

    大家一起:

    df.dropna(subset=['ShiftedPrice']).plot(x='date', y='ShiftedPrice')
    

    【讨论】:

      猜你喜欢
      • 2015-01-09
      • 2021-03-21
      • 2018-11-26
      • 2018-08-22
      • 1970-01-01
      • 2016-11-05
      • 2014-01-08
      • 1970-01-01
      • 2020-10-25
      相关资源
      最近更新 更多