当我使用运行 Anaconda3 的 Jupyterlab 将数据加载到 pandas 时遇到问题,因为我的虚拟机突然宕机了。启动后,我发现我的代码由于某种原因不再工作。这是我的代码:awsc = pd.DataFrame()json_pattern = os.path.join('logs_old/AWSCloudtrailLog/','*')file_list = glob.glob(json_pattern)for file in file_list: data = pd.read_json(file, lines=True) awsc = awsc.append(data, ignore_index = True)awsc = pd.concat([awsc, pd.json_normalize(awsc['userIdentity'])], axis=1).drop('userIdentity', 1)awsc.rename(columns={'type':'userIdentity_type', 'principalId':'userIdentity_principalId', 'arn':'userIdentity_arn', 'accountId':'userIdentity_accountId', 'accessKeyId':'userIdentity_accessKeyId', 'userName':'userIdentity_userName',}, inplace=True)当我运行代码时,它给了我这样的 KeyError 消息:---------------------------------------------------------------------------KeyError Traceback (most recent call last)~/anaconda3/envs/environment/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2888 try:-> 2889 return self._engine.get_loc(casted_key) 2890 except KeyError as err:pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()KeyError: 'userIdentity'The above exception was the direct cause of the following exception:有什么办法可以解决这个问题吗?问题是来自熊猫还是蟒蛇?
添加回答
举报
0/150
提交
取消