In [2]:
import pandas as pd
import numpy as np
In [3]:
pd.Timestamp('9/1/2016 10:05AM')
Out[3]:
In [4]:
pd.Period('1/2016')
Out[4]:
In [5]:
pd.Period('3/5/2016')
Out[5]:
In [8]:
t1 = pd.Series(list('abc'), [pd.Timestamp('2016-09-01'),
pd.Timestamp('2016-09-02'), pd.Timestamp('2016-09-03')])
t1
Out[8]:
In [9]:
type(t1.index)
Out[9]:
In [10]:
t2 = pd.Series(list('def'), [pd.Period('2016-09'), pd.Period('2016-10'), pd.Period('2016-11')])
t2
Out[10]:
In [11]:
type(t2.index)
Out[11]:
In [14]:
d1 = ['2 June 2013', 'Aug 29, 2014', '2015-06-26', '7/12/16']
ts3 = pd.DataFrame(data=np.random.randint(10,100,(4,2)), index=d1, columns=list('ab'))
ts3
Out[14]:
In [16]:
ts3.index = pd.to_datetime(ts3.index)
ts3
Out[16]:
In [17]:
pd.to_datetime('4.7.12', dayfirst=True)
Out[17]:
In [18]:
pd.Timestamp('9/3/2016') - pd.Timestamp('9/1/2016')
Out[18]:
In [20]:
pd.Timestamp('9/2/2016 8:10AM') + pd.Timedelta('12D 3H')
Out[20]:
In [22]:
dates = pd.date_range('10-01-2016', periods=9, freq='2W-SUN')
dates
Out[22]:
In [23]:
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[23]:
In [25]:
df.index.weekday_name
Out[25]:
In [26]:
df.diff()
Out[26]:
In [27]:
df.resample('M').mean()
Out[27]:
In [30]:
df['2017']
Out[30]:
In [31]:
df['2016-12']
Out[31]:
In [32]:
df['2016-12':]
Out[32]:
In [40]:
df.asfreq('M', method='ffill')
Out[40]:
In [44]:
import matplotlib.pyplot as plt
%matplotlib inline
df.plot()
Out[44]:
In [ ]: