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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.