【问题标题】:pandas df.plot.scatter fails but df.plot produces plotpandas df.plot.scatter 失败但 df.plot 产生情节
【发布时间】:2020-05-07 19:20:58
【问题描述】:

我想从 pandas df 生成数据散点图,示例如下。 我可以生成线图:

ax = df_stats.plot(x = 't', y = 't_TI_var_ws')
ax1 = ax.twinx()
df_stats.plot(x='t',y='t_TI_var_pwr',ax=ax1, color='g')

但是当我尝试使用 .scatter 绘制与散点图相同的数据时,我收到错误 KeyError: 't'

ax = df_stats.plot.scatter(x = 't', y = 't_TI_var_ws')
ax1 = ax.twinx()
df_stats.plot.scatter(x='t',y='t_TI_var_pwr',ax=ax1, color='g')

【问题讨论】:

  • 如果你这样做会发生什么:df_stats.plot(x='t',y='t_TI_var_pwr',ax=ax1, color='g', kind='scatter')
  • 同样的错误KeyError: 't'
  • 请提供样本数据
  • @YOLO type('t') 返回'str't 在变量资源管理器中被列为datetime

标签: python pandas python-2.7 dataframe plot


【解决方案1】:

看来您的列 to 是一个时间戳。要使用 scatter 它必须是一个浮点数。 您可以绘制散点图:

ax = df_stats.plot(x = 't', y='t_TI_var_pwr',style='o')      

【讨论】:

    猜你喜欢
    • 2021-10-17
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    相关资源
    最近更新 更多