求人口最大的國家各種解法問題
2020/06/12 上午 11:36
機器學習共學討論版
Shirley
觀看數:10
回答數:1
收藏數:0
最近參考了各位大神的解法,但JUPYTER還是報錯><
請問各個方法怎麼修改才能解決問題呢@@
《程式碼底家》
"PYTHON3"
import pandas as pd
data = {'country': ['A', 'B', 'C', 'D'],
'population': ['30000000', '2000000', '10000', '500']}
df = pd.DataFrame(data)
#法一
df.loc[df.iloc[:,1].argmax(),'country']
df.set_index("country").iloc[:,0].argmax()
#OUTPUT
#TypeError: reduction operation 'argmax' not allowed for this dtype
#法二
#data.sort_values(by='population', ascending=False)
#OUTPUT
#AttributeError: 'dict' object has no attribute 'sort_values'
#法三
#data[data['country'] == data['population'].max()]"
#OUTPUT
#AttributeError: 'list' object has no attribute 'max'
print(df)
感謝回答~