pandas apply lamba

import pandas as pd
import numpy as np

df = pd.DataFrame({'name':['Jack','Alex','Bob','Nancy','Mary','Alice','Jerry','Wolf'],
              'course':['Chinese','Math','Math','Chinese','Math','English','Chinese','English'],
              'grade':[1,1,2,2,2,2,3,3],
              'score':[85,95,91,78,89,60,87,79]})

vv = df.apply(lambda x:x['score']*2,axis=1)  #axis用于指定每次传入的是行数据
print('vv:',vv)
vv: 0    170
1    190
2    182
3    156
4    178
5    120
6    174
7    158
dtype: int64

你可能感兴趣的:(PYTHON,pandas)