comp-data / 2022-2023

The GitHub repository containing all the material related to the Data Science course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2022/2023).
14 stars 4 forks source link

Exercises: 4 #6

Open arcangelo7 opened 1 year ago

arcangelo7 commented 1 year ago

Create two data frames using the following two dictionaries:

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

Merge the two data frames, appending the second data frame as a new column to the first data frame.

arcangelo7 commented 1 year ago
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")