0

I am trying to convert a streamed list of values that are appended to a pandas dataframe and convert them to a 1 min ohlc data.

I am having issues with trying to get the resample done and have hit a wall.

Here is my data.

        Timestamp    Price   Symbol
0   1627933340985   0.0000      NaN
1   1627933342254  19.9052  USD/MXN
2   1627933345881  19.9052  USD/MXN
3   1627933345893  19.9052  USD/MXN
4   1627933350247  19.9052  USD/MXN
..            ...      ...      ...
86  1627933573930  19.9078  USD/MXN
87  1627933578959  19.9079  USD/MXN
88  1627933582942  19.9079  USD/MXN
89  1627933585753  19.9079  USD/MXN
90  1627933591925  19.9078  USD/MXN

This will keep getting updated but thats not important right now.

The timestamp is currently a string but I am having difficulty converting it so pandas can do a resample to ohlc data.

Thanks!

user1601716
  • 1,893
  • 4
  • 24
  • 53

1 Answers1

1

This is a unix timestamp in milliseconds. Convert it to a datetime object like this:

df['Timestamp'] = pd.to_datetime(df['Timestamp'], unit='ms')

Result:

index Timestamp Price Symbol
0 0 2021-08-02 19:42:20.985000 0 NaN
1 1 2021-08-02 19:42:22.254000 19.9052 USD/MXN
2 2 2021-08-02 19:42:25.881000 19.9052 USD/MXN
3 3 2021-08-02 19:42:25.893000 19.9052 USD/MXN
4 4 2021-08-02 19:42:30.247000 19.9052 USD/MXN
RJ Adriaansen
  • 9,131
  • 2
  • 12
  • 26