AttributeError: 'DataFrame' object has no attribute 'get_loc'
时间: 2023-07-30 20:07:52 浏览: 303
Apologies for the confusion caused. It seems like there was another typo in my previous response. Instead of using `get_loc()` method on the DataFrame, you can directly access the index of the column using the `index()` method of the columns.
Here's the corrected code:
```python
import pandas as pd
# Create a sample DataFrame
df = pd.DataFrame([[8108.854, 8078.825, 7997.861, 7911.848, 7873.547, 7906.965,
7989.997, 8072.625, 8108.854, 8078.825, 7997.861, 7911.848,
7873.547, 7906.965, 7989.997, 8072.626, 8108.854, 7.]],
columns=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R'])
# Find the column index with the maximum value
max_column_index = df.idxmax(axis=1)[0]
# Get the column position
column_position = df.columns.tolist().index(max_column_index)
print(f"The maximum value is in column {max_column_index}, at position {column_position}.")
```
This code should now run without any errors and print the desired output.
Once again, I apologize for any confusion caused by the previous response.
阅读全文