Given a dataframe with time series that looks like this:
Close
2015-02-20 14:00:00 1200.1
2015-02-20 14:10:00 1199.8
2015-02-21 14:00:00 1199.3
2015-02-21 14:10:00 1199.0
2015-02-22 14:00:00 1198.4
2015-02-22 14:10:00 1199.7
How can I get rid of the 'seconds' of the index so it looks like this:
Close
2015-02-20 14:00 1200.1
2015-02-20 14:10 1199.8
2015-02-21 14:00 1199.3
2015-02-21 14:10 1199.0
2015-02-22 14:00 1198.4
2015-02-22 14:10 1199.7
Thanks
If you just want strings, you could remove the trailing seconds with a regex ':\d\d$' .
Drop the index column of Pandas DataFrame We can remove the index column in existing dataframe by using reset_index() function. This function will reset the index and assign the index columns start with 0 to n-1.
Pandas Series: reset_index() function For a Series with a MultiIndex, only remove the specified levels from the index. Removes all levels by default. Just reset the index, without inserting it as a column in the new DataFrame. The name to use for the column containing the original Series values.
you can use map
and strftime
like this:
df.index =df.index.map(lambda t: t.strftime('%Y-%m-%d %H:%M'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With