天天看點

axis=1和axis=0的差別

axis=1和axis=0的差別

axis=1和axis=0的差別

一般axis=1,表示逐行讀取,符合使用者的了解順序

看官方手冊:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html?highlight=apply#pandas.DataFrame.apply

axis=1和axis=0的差別
import numpy as np
import pandas as pd
df = pd.DataFrame([[4, 9]] * 3, columns=['A', 'B'])
df.apply(lambda d: d.index,axis=1)
df.apply(lambda d: d.A+d.B,axis=1)      
axis=1和axis=0的差別
axis=1和axis=0的差別