I am trying to create an if statement that based on the pre-written script or conditions that I put in the list. It contains dictionary whereby key is the value that I am going to insert into cell if fulfill the condition. Just have a simple condition here but it could be based on 2 or more fields. It seems not working in the sample code below. It there any thing that I miss? Thanks
'''
import pandas as pd
def main():
df = pd.DataFrame({'Column_A': ['AAA','AAA','ABC','CDE'],
'checked': [0,0,1,0],
'duplicate': [True, True, False, False]})
simple_rules = [{'rollover': "(df['checked'] > 0)"}, {'mm_placement': "(df['checked'] == 1)"}]
df['status'] = ''
for rule in simple_rules:
for k, v in rule.items():
for i in range(len(df)):
if v:
df.at[i, 'status'] = k
print(df)
if __name__ == '__main__':
main()
'''
Aucun commentaire:
Enregistrer un commentaire