`timestamp` index should be DateTimeIndex, not floats
See original GitHub issueThe idea behind representing fetched prom data (or any data) as a Pandas DataFrame is to enable the processing of such data with all the powerful Pandas features.
But in case of a timeseries a major component of the data is the actual timestamps, which, to be usable, need to be represented as some form of datetime objects and not unix epoch timestamp floats, as they are now.
I propose to consider whether this shouldn’t be changed either by changing the default or at least having all functions give the option of returning the timestamps
index column converted to DateTimeIndex (similar to how Pandas’ DataFrame.read_csv()
has a parse_dates
argument).
The code for this might look like this (though maybe there’s a faster way):
newindex = df.index.to_series().apply(lambda ts: datetime.fromtimestamp(ts))
df.set_index(newindex, inplace=True)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Convert index floats back to datetime - python - Stack Overflow
The easiest is to to convert dates_ext to Timestamp before assigning it to the index of the new rows:
Read more >Time series / date functionality — pandas 1.5.2 documentation
pandas supports converting integer or float epoch times to Timestamp and DatetimeIndex . The default unit is nanoseconds, since that is how Timestamp...
Read more >Pandas: Converting integer or float epoch times to Timestamp ...
Write a Pandas program to convert integer or float epoch times to Timestamp and DatetimeIndex. Sample Solution: Python Code :
Read more >Part 5 - Working with Time Series Data | ArcGIS API for Python
Passing a series of dates by default returns a DatetimeIndex which can be used to index data in a Series or DataFrame ....
Read more >DateTime in Pandas: A Simple Guide for Beginners (2022)
If you're not familiar with the pandas library, you might like to try our ... If you pass a single integer or float...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah that makes sense 👍
Sounds good, I’ll assign myself to this then 😃
/assign chauhankaranraj
Hey @mmazur, I have added a PR (#234) to change the default dtypes for timestamps in the dataframe classes. Feel free to review it and let us know if you have any feedback!