當我使用運行 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
提交
取消