-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inplace option to DataFrame.update() #10730
Comments
can you show an example of your use case. As far as the default, this ship has sailed, would be better to introduce a |
I first encountered update as an answer to my stackoverflow question: regarding how to a "parallell lookup" from all rows of one DataFrame by the values of another DataFrame. In that example it might be useful to directly after the call to update() e.g. write the resulting dataframe to a csv file. |
I had a similar feeling. Is there a way to do this in a more functional way? |
My use case is: # combine three datetime series referring to periods that partially overlap
overall_forecast = long_term_forecast.update(medium_term_forecast).update(short_term_forecast) I can't use |
@giuliobeseghi If I understand correctly, it sounds like your use case would be solved by using combine_first instead of update? Combine Series values, choosing the calling Series's values
first. Result index will be the union of the two indexes
Parameters
----------
other : Series |
You are right. Thanks for that, I got confused with the example: I might have to keep the import pandas as pd
import numpy as np
s = pd.Series([1, 2, 3, 4, 5])
t = pd.Series([10, 11, 12], index=range(3, 6))
t.iloc[1] = np.nan
print(t)
res = s.reindex(t.index | s.index)
res.loc[t.index] = t.to_numpy()
print(res) It would be good if |
Shall we suggest "For non-inplace update consider |
I think there is no way to do this sort of pick the values from a new DataFrame in a functional manner I guess maybe |
I think with the more active discussion about deprecating/retooling |
Currently
DataFrame.update()
modifies the dataframe in place. I feel this is not symmetric to how most other methods work, e.g.set_index()
, that returns a newDataFrame
. It is probably too late to change this default behavior (isi it?), but if at the very least aninplace
option was added (with default valueTrue
to support the current behaviour), it will be easier to chain a sequence of operators that includesupdate()
.The text was updated successfully, but these errors were encountered: