Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas change dtype to timestamp

pd.to_datetime(df.column)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: tkinter text blurry 
Python :: get the name of a file using os 
Python :: try open file 
Python :: python get desktop directory 
Python :: python printing to a file 
Python :: django radio button 
Python :: python check if number is in range 
Python :: pygame how to draw a rectangle 
Python :: twitter bot python 
Python :: how to delete a column from a dataframe in python 
Python :: how can item in list change in int in python 
Python :: pandas pad method 
Python :: keras.layers.simplernn 
Python :: how to resize tkinter window 
Python :: as type in pandas 
Python :: Taking a list of strings as input, our matching function returns the count of the number of strings whose first and last chars of the string are the same. Also, only consider strings with length of 2 or more. python 
Python :: lasso regression implementation python 
Python :: python sleep 1 second 
Python :: python check if 3 values are equal 
Python :: conda python update 
Python :: how to clean environment python 
Python :: python logging basicconfig stdout 
Python :: python opencv imresize 
Python :: check object type python 
Python :: train test split 
Python :: limit for loop python 
Python :: dataframe create 
Python :: python time library 
Python :: python get file name without dir 
Python :: Module "django.contrib.auth.hashers" does not define a "BcryptPasswordHasher" attribute/class 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =