assign是直接向DataFrame对象添加新的一列
示例:
import numpy as np
import pandas as pd
data = {'name':['lily','jack','hanson','bom'],'age':np.random.randint(15,25,size=4),'gerder':['F','M','M','F']}
df = pd.DataFrame(data)
df.assign(score=np.random.randint(60,100,size=4))
结果:
添加的列名不能用字符串表示