为了账号安全,请及时绑定邮箱和手机立即绑定

如何将 AWS CloudTrail JSON 日志读取到 pandas 数据帧中

如何将 AWS CloudTrail JSON 日志读取到 pandas 数据帧中

隔江千里 2023-09-26 14:29:27
当我使用运行 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 回答
  • 0 关注
  • 75 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信