Standardize subset of columns that contain NaNs

Viewed 66

I have a pandas df that contains 50 columns. The first row in the df is column names. I want to standardize only column 11 to 47. I first want to drop all rows that have a column value NaN across all 50 variables, and then standardize the columns 11 to 47 with $ (x - \bar{x})/sd $ using StandardScaler. I get an error and I dont know why, please know I am not a great coder and would appreciate any detailed help.

df=df.dropna()
df.iloc[: ,11:47]= StandardScaler(df.iloc[: ,11:47])

And get the error:

FutureWarning: Pass copy= column1 column2 ... column46 column47

[4001 rows x 36 columns] as keyword args. From version 1.0 (renaming of 0.25) passing these as positional arguments will result in an error warnings.warn(f"Pass {args_msg} as keyword args. From version "

1 Answers

Use df.at to access DataFrame

df.at[: ,11:47]= StandardScaler(df.iloc[: ,11:47])
Related