Reputation: 11
While I tried to give the ffill command with inplace as true for a particular column, it gave me a warning. However the result was correct as expected as I worked with only 1 column at a time.
>>> df['name'].ffill(inplace=True)
<stdin>:1: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.
For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.
>>>
However to have a good code as recommended, I wanted to try the method with inplace option still instead of assignment option given. However I'm not successful yet, not sure what mistake I'm making. Please help
>>> df.ffill({col: "name"}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'col' is not defined. Did you mean: 'cols'?
>>> df.ffill({cols: "name"}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> df.ffill({cols: name}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined
>>> df.ffill({cols: 'name'}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> df.ffill({col: name}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'col' is not defined. Did you mean: 'cols'?
>>> df.ffill({cols: name}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined
>>> df.ffill({cols: [name]}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined
>>> df.ffill({cols: ['name']}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>>
>>>
>>>
>>> df.ffill({cols: 'name'}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>>
>>>
>>>
>>>
>>> df.ffill({name: }, inplace=True)
File "<stdin>", line 1
df.ffill({name: }, inplace=True)
^
SyntaxError: expression expected after dictionary key and ':'
>>> df.ffill({'name' }, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: NDFrame.ffill() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given
>>> df.ffill('name', inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: NDFrame.ffill() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given
>>> df.ffill({'name'}, inplace=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: NDFrame.ffill() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given
>>>
df.ffill({cols: 'name'}, inplace=True)
to be successful without warning and do the update of df frame.
Upvotes: 1
Views: 477