As you can check in this question Here, the best way to add a column in Pandas 0.16+ is
df = df.assign(new_column = Something)
Where new_column is literaly the name of the new column (even if it is not written as a string).
This is a problem for me, as I want to add many columns, whose name is specified by a variable
I tried this:
for col in df.columns:
new_col_name = col + "_nancount"
test = test.assign(new_col_name = test[col].isna().sum())
It doesn't work: in this way, just one Column is added (and it's named "new_col_name")
The expected result is, given a table with columns ["A", "B", "C"] to have a table with columns ["A", "B", "C", "A_nancount", "B_nancount", "C_nancount"]
How can I do that?