We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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]
The text was updated successfully, but these errors were encountered:
No sometimes about it; Its a function of the type of the input.
With a list-like, you will get a DatetimeIndex with a scalar, you will get a Timestamp with a Series you will get a Series
DatetimeIndex
Timestamp
Series
So you get an output of like-kind to the input.
In [13]: pd.to_datetime(['20140101']) Out[13]: <class 'pandas.tseries.index.DatetimeIndex'> [2014-01-01] Length: 1, Freq: None, Timezone: None In [14]: pd.to_datetime(Series(['20140101'])) Out[14]: 0 2014-01-01 dtype: datetime64[ns]
Sorry, something went wrong.
Maybe this should be added to the docstring?
@jreback @teramind see #8921
No branches or pull requests
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
dftimes.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)
t0.head()
The text was updated successfully, but these errors were encountered: