In [1]:
import pandas as pd
import numpy as np
In [2]:
pd.Timestamp('9/1/2016 10:05AM')
Out[2]:
In [3]:
period=pd.Period('1/2016')
period
Out[3]:
In [4]:
pd.Period('3/5/2016')
Out[4]:
In [5]:
t1 = pd.Series(list('abc'), [pd.Timestamp('2016-09-01'), pd.Timestamp('2016-09-02'), pd.Timestamp('2016-09-03')])
t1
Out[5]:
In [6]:
type(t1.index)
Out[6]:
In [7]:
t2 = pd.Series(list('def'), [pd.Period('2016-09'), pd.Period('2016-10'), pd.Period('2016-11')])
t2
Out[7]:
In [8]:
type(t2.index)
Out[8]:
In [9]:
d1 = ['2 June 2013', 'Aug 29, 2014', '2015-06-26', '7/12/16']
ts3 = pd.DataFrame(np.random.randint(10, 100, (4,2)), index=d1, columns=list('ab'))
ts3
Out[9]:
In [10]:
type(ts3.index)
Out[10]:
In [11]:
ts3.index = pd.to_datetime(ts3.index)
ts3
Out[11]:
In [12]:
type(ts3.index)
Out[12]:
In [13]:
pd.to_datetime('4.7.12', dayfirst=True)
Out[13]:
In [14]:
pd.Timestamp('9/3/2016')-pd.Timestamp('9/1/2016')
Out[14]:
In [15]:
pd.Timestamp('9/2/2016 8:10AM') + pd.Timedelta('12D 3H')
Out[15]:
In [16]:
dates = pd.date_range('10-01-2016', periods=9, freq='2W-SUN')
dates
Out[16]:
In [17]:
df = pd.DataFrame({'Count 1': 100 + np.random.randint(-5, 10, 9).cumsum(),
'Count 2': 120 + np.random.randint(-5, 10, 9)}, index=dates)
df
Out[17]:
In [18]:
df.index.weekday_name
Out[18]:
In [19]:
df.diff()
Out[19]:
In [20]:
df.resample('M').mean()
Out[20]:
In [21]:
df['2017']
Out[21]:
In [22]:
df['2016-12']
Out[22]:
In [23]:
df['2016-12':]
Out[23]:
In [24]:
df.asfreq('W', method='ffill')
Out[24]:
In [25]:
import matplotlib.pyplot as plt
%matplotlib inline
df.plot();