import pandas as pd
row1list = [0, 1, 'rest', 'rant']
row2list = [1, 0, 'rest', 'or rant']
row3list = [0, 1, 'rest', 'stop']
df = pd.DataFrame([row1list, row2list, row3list],
columns=['Vegan Options', 'Vegetarian Options', 'col_abc', 'col_xyz'])
for col in ['Vegan Options', 'Vegetarian Options']:
df_filtered = df[df[col] == 1] # keep only the rows where col value == 1
del df_filtered[col] # delete the column you filtered on
有一种方法可以创建一个仅值==1的新数据帧,并仅保留其他列:
相关问题 更多 >
编程相关推荐