1

I am trying to produce a Regression/Scatterplot with a datetime.time object between the Amplitude of several Nerves and the Time they have been in use in a trial.

>>> 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

However sns.regplot(y=df.iloc[:, 1], x=df.iloc[:, 0]) causes a

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

I tried everything from here to there and several other links that I can't find anymore but haven't been able to do so. Is there anything I haven't seen yet?

Seneo
  • 87
  • 1
  • 11

1 Answers1

0

I solved it by

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

Code:

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]"])

This produces a SettingWithCopyWarning that can be disabled, but I'm not sure if that's advisable.

Seneo
  • 87
  • 1
  • 11