我想复制Excel中的数据集
我的python代码如下所示:
data_frames = [df_mainstore, df_store_A, df_store_B]
df_merged = reduce(lambda left,right: pd.merge(left,right,on=["Id_number"], how='outer'), data_frames)
print(df_merged)
由于我合并了多个数据帧(列编号和名称可能不同),因此写出在本example中完成的所有列也会很繁琐:
isY = lambda x:int(x=='Y')
countEmail= lambda row: isY(row['Store Contact A']) + isY(row['Store B Contact'])
df['Contact Email'] = df.apply(countEmail,axis=1)
我也很难表达:isY = lambda x:int(x=='@')
如何以Excel中类似的方式添加“联系人有电子邮件”列
您可以使用pandas.Series.str.contains
您可以使用
filter
选择其中包含Contact的列,然后使用str.contains
和右边的pattern for email address,最后您希望每行有any
,因此:相关问题 更多 >
编程相关推荐