0

Hej,

My time format of my datetime object is like this %M:%S.%f but python apparently does not identify it as so. I have this problem with multiple columns which I want to use for visualisation

data example:

0            7:42.3
1            7:51.9
2            7:48.3
3            7:44.2
4            8:01.7
           ...     
111          8:55.5
112          8:17.9
113          8:41.1
114             NaN
115             NaN
Name: CRS1, Length: 116, dtype: object

Tried this without success:

t = pd.to_datetime(df["CRS1"], format='%M:%S.%f')

In seaborn I can plot the data if time is plotted against rank but not if i switch variables around..iE. Athletes Name and Finish time -> TypeError: Neither the x nor y variable appears to be numeric.

enter image description here

Quite new to python, so would appreciate a good explanation to deal with this format. /Thanks!

buran
  • 13,682
  • 10
  • 36
  • 61
Hansson
  • 112
  • 6
  • 1
    If the first digit(s) really represents minutes, it should be zero padded. see https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior – Tranbi Jun 14 '22 at 13:33
  • `df["CRS1"] = pd.to_datetime(df["CRS1"].str.zfill(7), format='%M:%S.%f').dt.time` – Trenton McKinney Jun 14 '22 at 13:52
  • @TrentonMcKinney getting a new error with this approach AttributeError: Can only use .str accessor with string values! – Hansson Jun 14 '22 at 13:56
  • See [code](https://i.stack.imgur.com/9Lhu1.png). You could try `.dropna` on the column, but you can see in the linked image that it doesn't cause an issue. Make sure pandas is updated `conda update --all` – Trenton McKinney Jun 14 '22 at 14:08
  • Tried it multiple times even with reformatting the excel input. But pandas still does not identify the format "%M:%S.%f" for the time data. Can I share the file with you? – Hansson Jun 18 '22 at 15:06

0 Answers0