I have a dataframe (data) where one column('BEG_DT') is a string representation of a date in the format of YYYYmmdd (example 19490713 = 1949, July, 13).
data[data.columns[0:3]].head()
NCDC BEG_DT END_DT
1 10000001 19490713 19501115
2 10000001 19590701 19621001
3 10000001 19621001 19630129
4 10000001 19630129 19670125
5 10000001 19670125 19800205
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 277297 entries, 0 to 277296
Data columns (total 32 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 NCDC 277297 non-null object
1 BEG_DT 277297 non-null object
2 END_DT 277297 non-null object
type(data.iloc[1]['BEG_DT'])
str
I need to convert the BEG_DT column to a datetime column. When I use the following:
pd.to_datetime(data['BEG_DT'], format='%Y%m%d')
I get:
TypeError Traceback (most recent call last)
<ipython-input-98-61a349589cf7> in <module>
----> 1 pd.to_datetime(data['BEG_DT'], format='%Y%m%d')
TypeError: 'Series' object is not callable
I can recreate the same error with this toy example:
ser1 = ['A','B','C']
ser2 = ['19920525', '19430224','19590216']
adf=pd.DataFrame({'col1':['A','B','C'],'col2':['19920525', '19430224','19590216']})
adf
col1 col2
0 A 19920525
1 B 19430224
2 C 19590216
adf['Date']=pd.to_datetime(adf['col2'])
TypeError Traceback (most recent call last)
<ipython-input-111-48d6423da8db> in <module>
----> 1 adf['Date']=pd.to_datetime(adf['col2'])
TypeError: 'Series' object is not callable
I believe that the syntax is correct according to the Pandas to_datetime documentation, so my understanding of how this works is incorrect. Can someone explain what I am doing wrong?