Description
pandas.to_datetime() should not return different types.
Otherwise, all output should have methods like .head() and .tail() and .month()
import pandas as pd
import numpy as np
pd.options.display.mpl_style = 'default'
import matplotlib.pyplot as plt
x0['Month']=x0['Date'].month
data=np.random.rand(5)
data[4]=NaN
dfdata=pd.DataFrame({'Data':data})
times=['19990103','19990106','19990109','19990112','NaT']
dftimes = pd.to_datetime(times,format='%Y%m%d')
dftimes
Out[10]:
class 'pandas.tseries.index.DatetimeIndex'
dftimes.head
AttributeError Traceback (most recent call last)
in ()
----> 1 dftimes.head
AttributeError: 'DatetimeIndex' object has no attribute 'head'
'Download files'
import urllib
urllib.urlretrieve ("http://www.epa.gov/ttn/airs/airsaqs/detaildata/501files/Rd_501_88101_1999.Zip", "./data/Rd_501_88101_1999.zip")
'Unzip the files...'
import zipfile
import os.path
zfile = zipfile.ZipFile("./data/Rd_501_88101_1999.zip")
for name in zfile.namelist():
zfile.extract(name,'./data/')
import pandas as pd
import numpy as np
pd.options.display.mpl_style = 'default'
import matplotlib.pyplot as plt
%pylab inline
pm0=pd.io.parsers.read_table("./data/RD_501_88101_1999-0.txt","|",index_col=False,low_memory=False).drop(0)
x0=pm0[['Sample Value']].astype(float)
t0=pd.to_datetime(pm0['Date'],format='%Y%m%d')
print type(t0)
class 'pandas.core.series.Series'
t0.head()
1 1999-01-03
2 1999-01-06
3 1999-01-09
4 1999-01-12
5 1999-01-15
Name: Date, dtype: datetime64[ns]