Q:

Concatenate two data frames using the following conditions using python programming

belongs to collection: Python Pandas Exercises

0

Concatenate two data frames using the following conditions

Create two data frames using the following two dictionaries.

GermanCars = {'Company': ['Ford', 'Mercedes', 'BMV', 'Audi'], 
'Price': [23845, 171995, 135925 , 71400]} japaneseCars = {'Company': ['Toyota', 'Honda',
'Nissan', 'Mitsubishi '],
'Price': [29995, 23600, 61500 , 58900]}

Expected Output:

Python Pandas concatenate two data frames and create key for each data frame
Python Pandas concatenate two data frames and create a key for each data frame

 

All Answers

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

import pandas as pd

GermanCars = {'Company': ['Ford', 'Mercedes', 'BMV', 'Audi'], 'Price': [23845, 171995, 135925 , 71400]}
carsDf1 = pd.DataFrame.from_dict(GermanCars)

japaneseCars = {'Company': ['Toyota', 'Honda', 'Nissan', 'Mitsubishi '], 'Price': [29995, 23600, 61500 , 58900]}
carsDf2 = pd.DataFrame.from_dict(japaneseCars)

carsDf = pd.concat([carsDf1, carsDf2], keys=["Germany", "Japan"])
carsDf

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

total answers (1)

Merge two data frames using the following conditio... >>
<< Sort all cars by Price column using python program...