我使用类似于下面代码的长代码列表来检查&;创建一个值为“0”的列
如果数据帧(df)中不存在列
if 'E184' not in df: df['E184'] = 0
if 'E185' not in df: df['E185'] = 0
if 'E187' not in df: df['E187'] = 0
if 'E186' not in df: df['E186'] = 0
if 'E176' not in df: df['E176'] = 0
if 'E177' not in df: df['E177'] = 0
if 'E181' not in df: df['E181'] = 0
if 'E210' not in df: df['E210'] = 0
if 'E175' not in df: df['E175'] = 0
if 'E209' not in df: df['E209'] = 0
if 'E174' not in df: df['E174'] = 0
if 'E212' not in df: df['E212'] = 0
if 'E211' not in df: df['E211'] = 0
if 'E154' not in df: df['E154'] = 0
if 'E219' not in df: df['E219'] = 0
if 'E230' not in df: df['E230'] = 0
if 'E220' not in df: df['E220'] = 0
if 'E157' not in df: df['E157'] = 0
if 'E188' not in df: df['E188'] = 0
if 'E234' not in df: df['E234'] = 0
有没有一个简单而有效的方法来做到这一点
可以将^{} 与^{} 一起使用
您可以使用^{} :
设置
创建不在
中的列的字典df
结合新构造的数据帧
相关问题 更多 >
编程相关推荐