AttributeError: 'DataFrame' object has no attribute 'idmax'
时间: 2023-07-30 15:06:50 浏览: 134
Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
5星 · 资源好评率100%
I apologize for the confusion caused. It seems like there was a typo in my previous response. The correct method to find the column index with the maximum value in a DataFrame is `idxmax()` (notidmax()`). 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.get_loc(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. Again, I apologize for any confusion caused by the previous response.
阅读全文