Q:

Merge two data frames using the following condition using python programming

belongs to collection: Python Pandas Exercises

0

Merge two data frames using the following condition

Create two data frames using the following two Dicts, Merge two data frames, and append the second data frame as a new column to the first data frame.

Car_Price = {'Company': ['Toyota', 'Honda', 'BMV', 'Audi'],
'Price': [23845, 17995, 135925 , 71400]} car_Horsepower = {'Company': ['Toyota', 'Honda', 'BMV',
'Audi'], 'horsepower': [141, 80, 182 , 160]}

Expected Output:

Python Pandas merge two data frames and append new data frame as new column
Python Pandas merge two data frames and append new data frame as a new column

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

import pandas as pd

Car_Price = {'Company': ['Toyota', 'Honda', 'BMV', 'Audi'], 'Price': [23845, 17995, 135925 , 71400]}
carPriceDf = pd.DataFrame.from_dict(Car_Price)

car_Horsepower = {'Company': ['Toyota', 'Honda', 'BMV', 'Audi'], 'horsepower': [141, 80, 182 , 160]}
carsHorsepowerDf = pd.DataFrame.from_dict(car_Horsepower)

carsDf = pd.merge(carPriceDf, carsHorsepowerDf, on="Company")
carsDf

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< Concatenate two data frames using the following co...