May-16-2022, 01:01 AM
Caveat: I practically never use pandas, so my answer may not be too great.
I recently created some online polls to keep the students occupied. The csv file has for example 3 rows of Q1, 3 rows of Q2 and so on, similar to your 3 rows AAA, BBB.
So I adapted the poll csv, made 3 columns, id, Qnr, Result
Result contains nothing to start with, shows up in pandas as NaN.
If you search online, you can very quickly find answers for your particular problem. There is always more than 1 way to skin a cat!
I recently created some online polls to keep the students occupied. The csv file has for example 3 rows of Q1, 3 rows of Q2 and so on, similar to your 3 rows AAA, BBB.
So I adapted the poll csv, made 3 columns, id, Qnr, Result
Result contains nothing to start with, shows up in pandas as NaN.
If you search online, you can very quickly find answers for your particular problem. There is always more than 1 way to skin a cat!
import pandas as pd csv_file = '/home/pedro/myPython/pandas/test1.csv' df = pd.read_csv(csv_file) # try with these 2 I can't see how to combine them into 1 line! df.loc[df['Qnr'] == 'Q3', 'Result'] = 1 df.loc[df['Qnr'] != 'Q3', 'Result'] = 0 # or like this df['Result'] = df['Qnr'].apply(lambda x: 1 if x == 'Q3' else 0)