Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Convert a Pandas Column of Timestamps to Datetimes

import pandas as pd

#create DataFrame
df = pd.DataFrame({'stamps': pd.date_range(start='2020-01-01 12:00:00',
                             periods=6,
                             freq='H'),
                   'sales': [11, 14, 25, 31, 34, 35]})

#convert column of timestamps to datetimes
df.stamps = df.stamps.apply(lambda x: x.date())

#view DataFrame
df

	stamps	        sales
0	2020-01-01	11
1	2020-01-01	14
2	2020-01-01	25
3	2020-01-01	31
4	2020-01-01	34
5	2020-01-01	35
Source by www.statology.org #
 
PREVIOUS NEXT
Tagged: #Convert #Pandas #Column #Timestamps #Datetimes
ADD COMMENT
Topic
Name
8+9 =