Is there a faster way to zero out a pandas dataframe column than iterating through the dataframe like this (where A, B and C are the Column names):
while x < Framelength
dg.iloc[x, A] = 0
dg.iloc[x, B] = 0
dg.iloc[x, C] = 0
x+=1
I'm okay with zeroing out the entire dataframe if that would be faster
Check with
cols=[...]
df.loc[:, cols]=0
You can zero out the entire dataframe:
df[df.columns] = 0
or specify a list (iterable) of columns:
cols = list("ABC")
df[cols] = 0
For zeroing all rows in a column by calling the column's name you could do something like:
df["A"] = 0
df["B"] = 0
If you want to zero the entire DataFrame though I believe something like this should be quite efficient:
for c in df:
df[c].values[:] = 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With