【问题标题】:Seaborn regression plot with datetime object带有日期时间对象的 Seaborn 回归图
【发布时间】:2021-09-19 06:30:30
【问题描述】:

我正在尝试使用datetime.time 对象在多个神经的振幅和它们在试验中使用的时间之间生成回归/散点图。

>>> df.head()
   Amp strain 8 min [mA] Time in use [hh:mm]
0                    0.1            00:22:00
1                    0.0            00:46:00
2                    0.8            00:18:00
3                    0.3            00:23:00
4                    0.6            00:14:00

但是sns.regplot(y=df.iloc[:, 1], x=df.iloc[:, 0]) 会导致

TypeError: float() argument must be a string or a number, not 'datetime.time'

我尝试了从herethere 的所有内容,以及我无法再找到但无法找到的其他几个链接。有什么我还没看过的吗?

【问题讨论】:

  • 试试sns.regplot(y=df.iloc[:, 0], x=df.iloc[:, 1])
  • 虽然这会创建一个空图,但错误仍然存​​在

标签: python pandas datetime matplotlib seaborn


【解决方案1】:

我解决了

  1. converting the datetime object to string format
  2. replacing the colons
  3. converting the series to a numeric value

代码:

df["Time in use [hh:mm]"] = pd.to_numeric(df["Time in use [hh:mm]"].astype(str).str.replace(":", ""))
sns.regplot(y=df["Time in use [hh:mm]"], x=df["Amp strain 8 min [mA]"])

这会产生 SettingWithCopyWarningcan be disabled,但我不确定这是否可取。

【讨论】:

    猜你喜欢
    • 2018-08-10
    • 2019-07-09
    • 2017-08-06
    • 2017-11-05
    • 1970-01-01
    • 2021-09-19
    • 2020-09-03
    • 2017-08-20
    • 1970-01-01
    相关资源
    最近更新 更多