9951 explained code solutions for 126 technologies


python-pandasHow to convert timestamp to datetime


import pandas as pd

df = pd.DataFrame({
  'timestamp': ['1655977822', '1655977821', '1655977803'],
  'value': [1,2,3]
})

df['date'] = pd.to_datetime(df['timestamp'], unit='s')ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.to_datetime(

convert given column values to datetime type (will automatically parse given strings)

unit='s'

needed to treat given value as unix timestamp

'date'

column with datetime type