You are on page 1of 1

Python data science Missing links

Date&Time
We can create timestamp using pd.Timestamp
We can create period by using pd.Period
We can convert to to time stamp by using pd.to_datetime()
We can create date range using pd.date_range()
We can set week day name by using .weekday_name
We can groupby date using .resample(‘M’/’Y’/’D’/’T’)

import pandas as pd
import numpy as np

Timestamp pd.Timestamp('9/1/2016 10:05AM') Timestamp('2016-09-01 10:05:00')

Period pd.Period('1/2016 10:05 AM') Period('2016-01-01 10:05', 'T')

Converting to pd.to_datetime('2 June 2013') Timestamp('2013-06-02 00:00:00')


datetime we can set dayfirst=False,

yearfirst=False

Subtraction pd.Timestamp('9/3/2016')-pd.Timestamp('9/1/2016') Timedelta('2 days 00:00:00')

Date_Range dates = pd.date_range(start = '10-01-2016',end = '2017-01- DatetimeIndex(['2016-10-02', '2016-10-16',


22',freq='2W-SUN') '2016-10-30', '2016-11-13',
'2016-11-27', '2016-12-11', '2016-12-25',
We can set range/end date '2017-01-08',
'2017-01-22'],
dtype='datetime64[ns]', freq='2W-SUN')

Weekday_nam df.index.weekday_name
e
.loc for Date df.loc['2016':,]
DataFrame It will print everything from 2016 to end and rows
df['2016-12':]
It will print everything from 2016-12 to last
Groupby in df.resample('Y').sum()
Date It will groupby the year

You might also like