2021
03-19
03-19
pandas 添加空列并赋空值案例
创建测试dataframe:>>>importpandasaspd>>>df=pd.DataFrame([{'a':1,'b':2},{'a':3,'b':4}])>>>dfab012134添加两个空列>>>df[['c','d']]=df.apply(lambdax:('',''),axis=1,result_type='expand')>>>dfabcd012134当然,一列一列添加也是可以的>>>df['c']=''>>>df['d']=''但如果这样>>>df[['c','d']]=''KeyError:"Noneof[Index(['c','d'],dtype='object')]areinthe[columns]"补...
继续阅读 >