0

I have a dataframe with 7K columns and and same 7K values as indices

ex.

            c1 c2 .... c7000
          c1
          c2
          .
          .
          .
          c7000

I want to update each cell of this dataframe on some condition.

Can anyone please suggest fastest way to achieve this.

Shweta N
  • 11
  • 1

1 Answers1

0

Without knowing more about the question it is hard to give an answer. Please be more specific and ideally provide code to reproduce part of the dataframe that you are working with.

Usually apply() is used in such cases if I understand your description correctly:

df["update"] = df.apply(lambda row: 1 if row["conditional_column_boolean"] == "yes" else 0, axis = 1)

# for example
df = pd.DataFrame([[4, 9], [6, 2], [6, 10]], columns=['A', 'B'])
df.apply(lambda row: 1 if row["B"] > 8 else 0, axis = 1) # conditional column is column "B"
0    1
1    0
2    1
dtype: int64
freyberg
  • 367
  • 2
  • 9