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?

2
  • try sns.regplot(y=df.iloc[:, 0], x=df.iloc[:, 1]) Commented Jul 8, 2021 at 20:44
  • Although that creates an empty figure, the error remains the same Commented Jul 8, 2021 at 23:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.