如果.csv文件中某列下的一行包含1,则应使用python覆盖另一列中的同一行,否则应保留为空

I have a .csv file with about 300,000 rows. I have created a new column manually and I wish to extract information from some older columns but I can't do this manually because of the length of the file. The title of the older columns are Present, Online, Absent and the new column is Attendance. The older columns have values of 1 and 0 where the observation is true or false i.e if an observation came to the event then the "Present" column will have a value of 1 and if anything else, it carries a value of 0. Same with "online" and "absent" column.

I want the new column to take the information from the older ones, i.e if any of the older ones has a value of 1 the same row in "Attendance" should have a value of either "present", "online" or "absent" depending on which is true. I've been trying to do this using Pandas but haven't found a way that works for .csv files.

for i in f['Present']:
    if i == 1:
       f['Attendance'].write("present")

I don't mind if the solution works for one column and is repeated for the others. It doesn't have to work for all at once.

This is what it should look like

enter image description here

Thanks


For each row, will only one of Present, Online and Absent be true ?

yes. only one is true

kindly share a sample of ur dataframe, with ur expected output

thanks. does this work only in the internal python data-frame or is permanent on the .csv file?

It changes the dataframe only, you can export it to csv, do refer this pandas.pydata.org/pandas-docs/stable/reference/api/…

I tried it but its running forever...had to stop it myself

Refer this stackoverflow.com/questions/16923281/…