Home
Q&A
Education
Technology
Credit
General
Health
Insurance
Questions
Ask a Question
How to add values from two dataframes according to the persons in first column? Python Pandas
Home
Education
How to add values from two dataframes according...
asked
Jan 18, 2022
in
Education
by
JackTerrance
I have 2 data frames df1 Name 2010 2011 0 Jack 25 35 1 Jill 15 20 df2 Name 2010 2011 0 Berry 45 25 1 Jack 5 10 I want to create the third data frame by adding the values in these data frames Desired Output df3 Name 2010 2011 0 Jack 30 45 #add the values from df1 and df2 1 Jill 15 20 2 Berry 45 25 I have used the code df1.add(df2) Select the correct answer from above options
data-science
python
1
Answer
0
votes
answered
Jan 18, 2022
by
JackTerrance
Best answer
Concat both dfs and do a groupby and sum: print (pd.concat([df, df2]).groupby("Name", as_index=False).sum()) Name 2010 2011 0 Berry 45 25 1 Jack 30 45 2 Jill 15 20 Do check out Data Science with Python course which helps you understand from scratch
Related questions
0
votes
Q: Pandas add row at index 0 with dummy values
To the data frame df: Player Team Points Mean Price Value Gameweek 1 Jim Leeds 4.4 4.40 10.44 0.44 2 Jim ... scalar What am I missing? Select the correct answer from above options...
asked
Jan 18, 2022
in
Education
by
JackTerrance
python
data-science
0
votes
Q: Count the latest same values from column python
I have data like this: id a b c d 1 y y z z 2 y z y y 3 y y y y I want to count the value of "y" ... 1 2 2 1 3 4 Can anyone help me? Select the correct answer from above options...
asked
Jan 9, 2022
in
Education
by
JackTerrance
python
data-science
0
votes
Q: Combine two columns of text in dataframe in pandas/python
I have a 20 x 4000 dataframe in python using pandas. Two of these columns are named Year and quarter. I'd ... anyone help with that? Select the correct answer from above options...
asked
Jan 28, 2022
in
Education
by
JackTerrance
pandas
machine-learning
python
data-science
0
votes
Q: Merge two dataframes on closest matching datetime index
I have two data frames with the closest matching DateTime index, sometimes matching. An object is to merge two of ... I achieve this? Select the correct answer from above options...
asked
Jan 19, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: How to apply a function to a column given values from other columns?
I have the function and want to create a new column df['growth_factor'] which will have a derived value in it. ... can I achieve this? Select the correct answer from above options...
asked
Jan 19, 2022
in
Education
by
JackTerrance
python
data-science
0
votes
Q: How to create a column and fill it with new values based on a separate columns values
I have the dataset that has the no_employees column that is the str object. whats is a best way to create the new ... 1-5 |Very Small Select the correct answer from above options...
asked
Jan 19, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: Pandas dataframe compare values == none / nothing / null
I have 2 columns in the python dataframe. I want to check each row in my Column A for any value that ... for this particular purpose. Select the correct answer from above options...
asked
Jan 9, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: Converting python list of delimited items in to a pandas data frame
I have the list like this where items are separated by ":". x=['john:42:engineer', 'michael:29:doctor' ... engineer 1 michael 29 doctor Select the correct answer from above options...
asked
Jan 10, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: Calculate the percentage of a categorical column using conditional groupby and count in Python
I want to calculate a percentage, for each id, of True values from all rows of the id. Here an example ... df.num_true/df.num_col1_id Select the correct answer from above options...
asked
Jan 19, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: Converting a Pandas GroupBy output from Series to DataFrame
I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked
Jan 28, 2022
in
Education
by
JackTerrance
machine-learning
data-science
pandas
python
scikit-learn
0
votes
Q: Python summing values in a variable
In python, I want to sum all of the values in a variable. My code is x=100 y=200 for i in range(a,b) ... of all numbers which is 7500. Select the correct answer from above options...
asked
Jan 11, 2022
in
Education
by
JackTerrance
python
data-science
0
votes
Q: Using regex to find first bracketed content in Python 3
Here is my sample string: [true, {"name": "NameofItem", "amount": "1", "price": 100, "sellerName": " ... seem to make that work. Select the correct answer from above options...
asked
Jan 19, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: How to check if a word is in each row of a pandas dataframe
I have the pandas data frame with a column designated to town names. After each town name, I am adding a word " ... .csv', index=False) Select the correct answer from above options...
asked
Jan 19, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: How to check if a word is in each row of a pandas dataframe
I have the pandas data frame with the column designated to town names. After each town name, I am adding a word ... .csv', index=False) Select the correct answer from above options...
asked
Jan 19, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: How to replace date component of datetime64[ns] -Pandas with another date
I have this following datetime64[ns] type timestamps. x1=pd.Timestamp('2018-04-25 00:00:00') x2=pd.Timestamp('2020- ... -04-25 00:53:00 Select the correct answer from above options...
asked
Jan 9, 2022
in
Education
by
JackTerrance
data-science
python
...