Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (19.9k points)

I have a list of 3 DataFrames x, where each DataFrame has 3 columns. It looks like

1   2   T/F

4   7   False

4   11  True

4   20  False

4   25  True

4   40  False

What I want to do is set the value of each row in column 'T/F' to False for each DataFrame in list x

I attempted to do this with the following code

rang = list(range(len(x))) # rang=[0,1,2]

for i in rang:

    x[i].iloc[:len(x), 'T/F'] = False

The code compiled, but it didn't appear to work.

1 Answer

0 votes
by (25.1k points)

It's best to iterate over the actual dataframes and update the columns with:

for df in [df1, df2]:

    df['T/F'] = False

Browse Categories