KeyError: "None of [Index(['x1', 'x2'], dtype='object')] are in the [columns]"
时间: 2024-01-27 22:02:56 浏览: 149
gl-to-dtype:将 gl 类型转换为 dtype 字符串
This error occurs when you are trying to access a column that does not exist in the DataFrame. In this case, the columns 'x1' and 'x2' are not present in the DataFrame.
To fix this error, you need to check the column names in your DataFrame and ensure that they match the names you are trying to access. You can use the `df.columns` attribute to print out the column names and verify them.
If the column names are different, you can rename them using the `df.rename()` method. Alternatively, you can create new columns with the desired names and populate them with the data from the existing columns.
阅读全文