Proper way to utilize .loc in python's pandas -
when trying change column of numbers object
float
dtypes using pandas dataframes, receive following warning:
a value trying set on copy of slice dataframe. try using .loc[row_indexer,col_indexer] = value instead
now, code runs fine, proper , intended way avoid warning , still achieve goal of:
df2[col] = df2[col].astype('float')
let noted df2 subset of df1 using condition similar to:
df2 = df1[df1[some col] == value]
use copy
method. instead of:
df2 = df1[df1[some col] == value]
just write:
df2 = df1[df1[some col] == value].copy()
initially, df2
slice of df1
, not new dataframe. why, when try modify it, python raises error.
Comments
Post a Comment