如何繪制該圖中似乎最大的前 5 個值?( Wii, NES, GB, DS, X360)
sns.violinplot(x=df['Global_Sales'],y=df['Platform'],data=df)

uj5u.com熱心網友回復:
確保x和y是列名?,然后對data引數進行排序/過濾:
要么使用
nlargest(最快):sns.violinplot( x='Global_Sales', y='Platform', data=df.nlargest(5, 'Global_Sales') )或
sort_values與tail:... data=df.sort_values('Global_Sales').tail(5)或
sort_values(ascending=False)與head:... data=df.sort_values('Global_Sales', ascending=False).head(5)
?在OP的代碼,x并且y是列資料(x=df['Global_Sales']),而不是列的名稱(x='Global_Sales')。如果x和y是實際資料,data引數將被忽略,因此df需要在繪圖命令之前進行排序/過濾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/362623.html
標籤:Python 熊猫 matplotlib
