I have the following returned from an API Call as part of a larger dataset:
{'Time': datetime.datetime(2017, 5, 21, 18, 18, 1, tzinfo=tzutc()), 'Price': '0.052600'}
{'Time': datetime.datetime(2017, 5, 21, 18, 18, 1, tzinfo=tzutc()), 'Price': '0.052500'}
Ideally I would use the timestamp as an index on the pandas data frame however this appears to fail as there is a duplicate when converting to JSON:
df = df.set_index(pd.to_datetime(df['Timestamp']))
print(new_df.to_json(orient='index'))
ValueError: DataFrame index must be unique for orient='index'.
Any guidance on the best way to deal with this situation? Throw away one datapoint? The time does not get more fine-grain than to the second, and there is obviously a price change during that second.
You could use .duplicated to keep first or last entry. Have a look at pandas.DataFrame.duplicated
I think you can change duplicates datetimes by adding
ms
bycumcount
andto_timedelta
: