File dataexample_df.txt:
2020-12-04_163024 26.15 26.37 19.40 24.57
2020-12-04_163026 26.15 26.37 19.20 24.57
2020-12-04_163028 26.05 26.37 18.78 24.57
I want to read it in as pandas dataframe where the index column has only the time part in format '%H:%M:%S', without the date.
import pandas as pd
df = pd.read_csv("dataexample_df.txt", sep=' ', header=None, index_col=0)
print(df)
Output:
1 2 3 4
0
2020-12-04_163024 26.15 26.37 19.40 24.57
2020-12-04_163026 26.15 26.37 19.20 24.57
2020-12-04_163028 26.05 26.37 18.78 24.57
However, wanted output:
1 2 3 4
0
16:30:24 26.15 26.37 19.40 24.57
16:30:26 26.15 26.37 19.20 24.57
16:30:28 26.05 26.37 18.78 24.57
I have tried different date_parser= -functions (cf. Answers in Parse_dates in Pandas)
but get only error messages. Also, somewhat relevant is Python/Pandas convert string to time only but no luck, I'm stuck. I'm using Python 3.7.