数据分析:类型错误:"模块"对象不可调用



我清理了一些数据并遇到了TypeError,我无法弄清楚我的代码到底出了什么问题。任何帮助将不胜感激,谢谢!

# use loop to merge date and time into DateTime (w/progress bar)
def create_datetime_axis(daf):
datetime_axis = []
for row_n in tqdm(range(len(daf))):
srs = daf.iloc[row_n, :]
datetime_axis.append(datetime.strptime(''.join((srs['DATE'], srs['TIME'])), '%m/%d/%Y%H:%M').strftime('%m/%d/%Y %H:%M'))
return datetime_axis
In [61]:
# drop the TIME column and replace the DATE column with the new and improved DATETIME
filtered_df = df.copy()
filtered_df['DATE'] = create_datetime_axis(filtered_df)
filtered_df.drop('TIME', axis=1, inplace=True)
filtered_df.rename(columns={'DATE':'DATETIME'}, inplace=True)
filtered_df
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-61-f651516bbd66> in <module>
1 # drop the TIME column and replace the DATE column with the new and improved DATETIME
2 filtered_df = df.copy()
----> 3 filtered_df['DATE'] = create_datetime_axis(filtered_df)
4 filtered_df.drop('TIME', axis=1, inplace=True)
5 filtered_df.rename(columns={'DATE':'DATETIME'}, inplace=True)
<ipython-input-60-0e8f272e1aee> in create_datetime_axis(daf)
2 def create_datetime_axis(daf):
3     datetime_axis = []
----> 4     for row_n in tqdm(range(len(daf))):
5         srs = daf.iloc[row_n, :]
6         datetime_axis.append(datetime.strptime(''.join((srs['DATE'], srs['TIME'])), '%m/%d/%Y%H:%M').strftime('%m/%d/%Y %H:%M'))
TypeError: 'module' object is not callable

我认为您需要将其更改为:

# use loop to merge date and time into DateTime (w/progress bar)
def create_datetime_axis(daf):
datetime_axis = []
for row_n in tqdm.tqdm(range(len(daf))):
srs = daf.iloc[row_n, :]
datetime_axis.append(datetime.strptime(''.join((srs['DATE'], srs['TIME'])), '%m/%d/%Y%H:%M').strftime('%m/%d/%Y %H:%M'))
return datetime_axis

或将import tqdm更改为from tqdm import tqdm

最新更新