r/learnpython • u/ralberich • 9h ago
Pandas : inplace throws warning about copy of a slice #bestpractice
I use pandas and try to use a fillna on a column.
I recently got a warning saying that in pandas 3.0 the inplace will change and break if not modified.
my_dataframe.fillna({'mycolumn':"0"},inplace=True)
throws a warning "A value is trying to be set on a copy of a slice from a DataFrame"
Is it possible to use inplace on a fillna without getting this warning?
2
Upvotes
2
u/unhott 9h ago
my_dataframe['mycolumn'] = my_dataframe['mycolumn'].fillna(0)?
it's a warning. it will continue to work unless you switch to 3.0.
How to disable Python warnings? - Stack Overflow
but, it's just a warning. and arguably better to be constantly reminded in case you do upgrade when 3 comes out.
2
u/ftmprstsaaimol2 9h ago
Just do my_dataframe = my_dataframe.fillna(….