I will comment that with inplace=True df is updated and the return is None so by then setting df = None the result of that code will not work. Use either df.drop(.., inplace=True) or df = df.drop(..). Have you checked that column name 'Label' is there, e.g. with df.loc...
When trying to drop a non existing column in pandas dataframe it throw a KeyError stating that "['B1'] not found in axis" It is better if the wording was more specific like : should be "['B1'] not found in columns" because I specified that I want to delete columns. The same thing...
KeyError: “[‘CLIENT_IP‘, ‘ SESSION_ID‘, ‘ TYPE‘,] not found in axis”,程序员大本营,技术文章内容聚合第一站。
'Paris', 'London']} df = pd.DataFrame(data) # 选择单个列 selected_column = 'Age' if selected_column in df.columns: subset = df[selected_column] print(subset) else: print("Column not found.") # 选择多个列 selected_columns
returnself._get_label(key,axis=axis) File~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexing.py:1260in_get_label returnself.obj.xs(label,axis=axis) File~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\generic.py:4056inxs ...
in _get_label return self.obj.xs(label, axis=axis) File "C:\xxxx\miniconda3\lib\site-packages\pandas\core\generic.py", line 3739, in xs loc = index.get_loc(key) File "C:\xxxx\miniconda3\lib\site-packages\pandas\core\indexes\range.py", line 354, in get_loc raise KeyError(key) ...
in _get_grouper in_axis, name, gpr = True, gpr, obj[gpr] File "/usr/local/Python-3.5.2/lib/python3.5/site-packages/pandas/core/frame.py", line 1997, in __getitem__ return self._getitem_column(key) File "/usr/local/Python-3.5.2/lib/python3.5/site-packages/pandas/core/frame.py"...