首先看我們要用到的畫圖函數:
DataFrame.
plot
(x=None, y=None, kind='line', ax=None, subplots=False, sharex=None,sharey=False, layout=None, figsize=None, use_index=True, title=None, grid=None,legend=True, style=None, logx=False, logy=False, loglog=False, xticks=None, yticks=None,xlim=None, ylim=None, rot=None, fontsize=None, colormap=None, table=False, yerr=None,xerr=None, secondary_y=False, sort_columns=False, **kwds)
當然還有其他常用操作今天主要以這個爲例。https://mp.csdn.net/postedit/83993002
以西瓜數據集爲例進行代碼分析:
wmdf = pd.read_csv('watermelon3_0.csv')
wmdf.describe()
num density sugar
count 17.000000 17.000000 17.000000
mean 9.000000 0.532647 0.212824
std 5.049752 0.166906 0.119879
min 1.000000 0.243000 0.042000
25% 5.000000 0.403000 0.103000
50% 9.000000 0.593000 0.211000
75% 13.000000 0.657000 0.267000
max 17.000000 0.774000 0.460000
對上面的統計分析進行畫圖:
wmdf.describe().plot(title = 'analysis')
但是橫座標並沒有標出刻度,我們看函數定義中的參數:
use_index=True,就是使用index作爲x軸的刻度。
但是爲什麼還是沒有畫出來呢?原來還有另一個參數,xticks=None,把這個參數設置如下
wmdf.describe().plot(title = 'analysis',xticks = range(0,9))
此時終於有了刻度,如果我們不希望用index做刻度,只需要將use_index參數設置爲False即可。
wmdf.describe().plot(use_index = False, title = 'analysis',xticks = range(0,9))
這裏是我自己編程時遇到的,大家有其他的歡迎補充!