亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 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 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號