Update Values in a dataframe by merging
up vote
0
down vote
favorite
I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.
The rows and the columns that are in the latter appear in the first one as well:
print(inventory_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 0 0 0
11/09/18 0 0 0
12/09/18 0 0 0
...
print(final_inspect)
dt_op Prod_1
10/09/18 10
11/09/18 2
12/09/18 5
I would like to update the values in inventory_df, obtaining the following dataframe:
print(updated_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 10 0 0
11/09/18 2 0 0
12/09/18 5 0 0
...
I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:
TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
How can I merge the first two frames to create the updated one?
N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.
python pandas merge
add a comment |
up vote
0
down vote
favorite
I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.
The rows and the columns that are in the latter appear in the first one as well:
print(inventory_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 0 0 0
11/09/18 0 0 0
12/09/18 0 0 0
...
print(final_inspect)
dt_op Prod_1
10/09/18 10
11/09/18 2
12/09/18 5
I would like to update the values in inventory_df, obtaining the following dataframe:
print(updated_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 10 0 0
11/09/18 2 0 0
12/09/18 5 0 0
...
I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:
TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
How can I merge the first two frames to create the updated one?
N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.
python pandas merge
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.
The rows and the columns that are in the latter appear in the first one as well:
print(inventory_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 0 0 0
11/09/18 0 0 0
12/09/18 0 0 0
...
print(final_inspect)
dt_op Prod_1
10/09/18 10
11/09/18 2
12/09/18 5
I would like to update the values in inventory_df, obtaining the following dataframe:
print(updated_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 10 0 0
11/09/18 2 0 0
12/09/18 5 0 0
...
I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:
TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
How can I merge the first two frames to create the updated one?
N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.
python pandas merge
I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.
The rows and the columns that are in the latter appear in the first one as well:
print(inventory_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 0 0 0
11/09/18 0 0 0
12/09/18 0 0 0
...
print(final_inspect)
dt_op Prod_1
10/09/18 10
11/09/18 2
12/09/18 5
I would like to update the values in inventory_df, obtaining the following dataframe:
print(updated_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 10 0 0
11/09/18 2 0 0
12/09/18 5 0 0
...
I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:
TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
How can I merge the first two frames to create the updated one?
N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.
python pandas merge
python pandas merge
edited Nov 19 at 14:25
asked Nov 19 at 12:31
Alessandro Ceccarelli
216210
216210
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Use df.update()
-
inventory_df.update(final_inspect)
Output
dt_op Prod_1 Prod_2
0 10/09/18 10 0
1 11/09/18 2 0
2 12/09/18 5 0
This by default implements a join='left
, wherein you can take care of non-matching na values as you wish
It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
– Alessandro Ceccarelli
Nov 19 at 14:22
@AlessandroCeccarelli It updates thedf
inplace, i.e. theinventory_df
is updated directly
– Vivek Kalyanarangan
Nov 19 at 14:25
I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
– Alessandro Ceccarelli
Nov 19 at 14:39
Thats funny, not sure what might be going wrong, working fine for me :(
– Vivek Kalyanarangan
Nov 19 at 14:43
It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
– Alessandro Ceccarelli
Nov 19 at 16:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Use df.update()
-
inventory_df.update(final_inspect)
Output
dt_op Prod_1 Prod_2
0 10/09/18 10 0
1 11/09/18 2 0
2 12/09/18 5 0
This by default implements a join='left
, wherein you can take care of non-matching na values as you wish
It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
– Alessandro Ceccarelli
Nov 19 at 14:22
@AlessandroCeccarelli It updates thedf
inplace, i.e. theinventory_df
is updated directly
– Vivek Kalyanarangan
Nov 19 at 14:25
I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
– Alessandro Ceccarelli
Nov 19 at 14:39
Thats funny, not sure what might be going wrong, working fine for me :(
– Vivek Kalyanarangan
Nov 19 at 14:43
It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
– Alessandro Ceccarelli
Nov 19 at 16:12
add a comment |
up vote
0
down vote
accepted
Use df.update()
-
inventory_df.update(final_inspect)
Output
dt_op Prod_1 Prod_2
0 10/09/18 10 0
1 11/09/18 2 0
2 12/09/18 5 0
This by default implements a join='left
, wherein you can take care of non-matching na values as you wish
It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
– Alessandro Ceccarelli
Nov 19 at 14:22
@AlessandroCeccarelli It updates thedf
inplace, i.e. theinventory_df
is updated directly
– Vivek Kalyanarangan
Nov 19 at 14:25
I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
– Alessandro Ceccarelli
Nov 19 at 14:39
Thats funny, not sure what might be going wrong, working fine for me :(
– Vivek Kalyanarangan
Nov 19 at 14:43
It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
– Alessandro Ceccarelli
Nov 19 at 16:12
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Use df.update()
-
inventory_df.update(final_inspect)
Output
dt_op Prod_1 Prod_2
0 10/09/18 10 0
1 11/09/18 2 0
2 12/09/18 5 0
This by default implements a join='left
, wherein you can take care of non-matching na values as you wish
Use df.update()
-
inventory_df.update(final_inspect)
Output
dt_op Prod_1 Prod_2
0 10/09/18 10 0
1 11/09/18 2 0
2 12/09/18 5 0
This by default implements a join='left
, wherein you can take care of non-matching na values as you wish
answered Nov 19 at 12:38
Vivek Kalyanarangan
4,3681726
4,3681726
It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
– Alessandro Ceccarelli
Nov 19 at 14:22
@AlessandroCeccarelli It updates thedf
inplace, i.e. theinventory_df
is updated directly
– Vivek Kalyanarangan
Nov 19 at 14:25
I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
– Alessandro Ceccarelli
Nov 19 at 14:39
Thats funny, not sure what might be going wrong, working fine for me :(
– Vivek Kalyanarangan
Nov 19 at 14:43
It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
– Alessandro Ceccarelli
Nov 19 at 16:12
add a comment |
It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
– Alessandro Ceccarelli
Nov 19 at 14:22
@AlessandroCeccarelli It updates thedf
inplace, i.e. theinventory_df
is updated directly
– Vivek Kalyanarangan
Nov 19 at 14:25
I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
– Alessandro Ceccarelli
Nov 19 at 14:39
Thats funny, not sure what might be going wrong, working fine for me :(
– Vivek Kalyanarangan
Nov 19 at 14:43
It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
– Alessandro Ceccarelli
Nov 19 at 16:12
It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
– Alessandro Ceccarelli
Nov 19 at 14:22
It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
– Alessandro Ceccarelli
Nov 19 at 14:22
@AlessandroCeccarelli It updates the
df
inplace, i.e. the inventory_df
is updated directly– Vivek Kalyanarangan
Nov 19 at 14:25
@AlessandroCeccarelli It updates the
df
inplace, i.e. the inventory_df
is updated directly– Vivek Kalyanarangan
Nov 19 at 14:25
I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
– Alessandro Ceccarelli
Nov 19 at 14:39
I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
– Alessandro Ceccarelli
Nov 19 at 14:39
Thats funny, not sure what might be going wrong, working fine for me :(
– Vivek Kalyanarangan
Nov 19 at 14:43
Thats funny, not sure what might be going wrong, working fine for me :(
– Vivek Kalyanarangan
Nov 19 at 14:43
It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
– Alessandro Ceccarelli
Nov 19 at 16:12
It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
– Alessandro Ceccarelli
Nov 19 at 16:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374729%2fupdate-values-in-a-dataframe-by-merging%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown