我有一个名为batch_df
的df,我在df中添加了“as_percentage”。如果小时数为Nan,则设置为0。PyCharm中的代码运行良好,但当我在终端上运行时,出现了一个错误:请帮助!
Traceback (most recent call last):
File "/Users/vic_ong/dev/resource-management/generateBatch.py", line 166, in main()
File "/Users/vic_ong/dev/resource-management/generateBatch.py", line 51, in main
batch_df.loc[pd.isna(batch_df['hours']) == False, 'as_percentage'] = 0 AttributeError: 'module' object has no attribute 'isna'
编辑--我的代码如下所示:
#!/usr/bin/env python2
import lib
import pandas as pd
import datetime
import os
pd.set_option('expand_frame_repr', False)
# get directories
batchInputDir = '/Users/vic_ong/dev/resource-management/data/input/batchUpload'
def main():
# start timer
start_time = datetime.datetime.now()
# walk into every csv file in batchUpload and concatenate them into one df
list_ = []
for root, dirs, files in os.walk(batchInputDir):
for file in files:
if file.endswith('.csv'):
df = pd.read_csv(os.path.join(batchInputDir, file), index_col=None, header=0)
list_.append(df)
batch_df = pd.concat(list_)
batch_df = batch_df.dropna(how='all')
batch_df.reset_index(drop=True, inplace=True)
# clean data frame
# rename to standardized column names
batch_df.rename(columns={'Resource Name': 'name',
'Hours': 'hours'},
inplace=True)
# determine if value given was a percentage
batch_df['as_percentage'] = 1
batch_df.loc[pd.isna(batch_df['hours']) == False, 'as_percentage'] = 0
print batch_df.head
if __name__ == '__main__':
main()
批量样品:
name hours as_percentage
vic Nan 1
vic1 Nan 1
pandas.isna = pandas.isnull
这是我的权宜之计吗The ^{} alias for ^{} was only added in version 0.21 (0.22是截至2018年1月的最新版本);在0.20和更早版本上,它不存在;您必须使用旧的(并且仍然受支持的)名称
isnull
。请更新您的pandas
安装,或使用旧名称。相关问题 更多 >
编程相关推荐