我有一个名为batch_df的df,我在df中添加了'as_percentage‘。如果时间为Nan,则将as_percentage设置为0。代码在PyCharm中运行良好,但是当我在终端上运行它时,我得到了以下错误:请帮助!
回溯(最近一次调用): 文件"/Users/vic_ong/dev/resource-management/generateBatch.py",第166行,在main()中 文件"/Users/vic_ong/dev/resource-management/generateBatch.py",第51行,主 Batch_df.loc[pd.isna(批处理_df‘时数’) == False,'as_percentage'] =0 AttributeError:‘模块’对象没有属性'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()batch_df样本:
name hours as_percentage vic Nan 1 vic1 Nan 1
发布于 2018-01-18 02:58:47
was only added in version 0.21 (0.22是2018年1月的最新版本);在0.20及更早版本上,它不存在;您必须使用旧的(并且仍然支持) isnull名称。更新您的pandas安装,或者使用旧的名称。
发布于 2019-04-27 22:07:04
pandas.isna = pandas.isnull帮我解决这个问题
https://stackoverflow.com/questions/48313035
复制相似问题