這里是一份持續(xù)更新的常用參數(shù)使用文檔
inplace, axis...
import pandas as pd
import tushare as ts
inplace
簡單易懂的參數(shù),表示初始的數(shù)據(jù)是否發(fā)生變化。當(dāng)我們對數(shù)據(jù)進行再加工,可以先inplace=False來觀察生成的效果,得到理想中的數(shù)據(jù)之后再inplace=True
movies = ts.month_boxoffice()
movies.head()

image.png
假設(shè)我們希望電影按照口碑來進行排序
movies.sort_values('WomIndex', ascending=False).head()

image.png
movies.head()

image.png
可以看出movie是沒有發(fā)生變化的,因為sort_values中的inplace默認(rèn)參數(shù)是False,下面用inplace=True來改變movie數(shù)據(jù)本身。
(shift + tab juypter 操作)

image.png
movies.sort_values('WomIndex', ascending=False, inplace=True)
movies.head()

image.png
axis
axis軸線,其實表示的是你希望對數(shù)據(jù)操作的方向。axis=0,表示水平方向(rows)。axis=1,表示垂直方向(columns)。
比如上例中axis=0,就表示我們按照每個row的womIndex來進行排序。這個時候使用axis=1,會直接報錯。
還是使用movies,來看一下axis=1的效果。
movies.avgboxoffice = movies.avgboxoffice.astype(float)
movies.avgshowcount = movies.avgshowcount.astype(float)
movies.loc[:, ['avgboxoffice', 'avgshowcount']].sum(axis=0)
avgboxoffice 364.0
avgshowcount 219.0
dtype: float64
movies.loc[:, ['avgboxoffice', 'avgshowcount']].sum(axis=1)
6 48.0
0 75.0
7 50.0
8 46.0
2 52.0
3 54.0
4 53.0
1 59.0
5 52.0
9 49.0
10 45.0
dtype: float64
當(dāng)axis=0的時候,計算列avgboxoffice,avgshowcount每行的加總
當(dāng)axis=1的時候,計算每行avgboxoffice,avgshowcount列的加總