<jupyter_start><jupyter_text>Weclome to Pandas DataFrames exercises In this exercise, we are using Automobile Dataset for data analysis. This Dataset has different characteristics of an auto such as body-style, wheel-base, engine-type, price, mileage, horsepower.you can find the data in the data folder under `Automobile_data.csv`name  Exercise 1:From the given dataset print the first and last five rows![pandas_printing_first_5_rows.webp](attachment:pandas_printing_first_5_rows.webp)Python Pandas printing first 5 rows ![pandas_printing_last_5_rows.webp](attachment:pandas_printing_last_5_rows.webp)Python Pandas printing last 5 rows<jupyter_code>import pandas as pd

df = pd.read_csv('data/Automobile_data.csv')

pd.set_option('display.max.rows',None)<jupyter_output><empty_output><jupyter_text>First 5 rows:<jupyter_code>df.head(5)<jupyter_output><empty_output><jupyter_text>Last 5 rows:<jupyter_code>df.tail(5)<jupyter_output><empty_output><jupyter_text>Exercise 2:**Clean the dataset and update the CSV file**Replace all column values which contain `?`, `n.a`, or `NaN`.  Missing values befor:<jupyter_code>print('NaN\n',df.isnull().sum())<jupyter_output>NaN
 index               0
company             0
body-style          0
wheel-base          0
length              0
engine-type         0
num-of-cylinders    0
horsepower          0
average-mileage     0
price               3
dtype: int64<jupyter_text>Missing values after:<jupyter_code>df=df.dropna()
print('NaN\n',df.isnull().sum())
df
##print('Shape : \n',df.shape)
##print(df.info())
##print('Description : \n',df.describe())<jupyter_output>NaN
 index               0
company             0
body-style          0
wheel-base          0
length              0
engine-type         0
num-of-cylinders    0
horsepower          0
average-mileage     0
price               0
dtype: int64<jupyter_text>Exercise 3:**Find the most expensive car company name**Print most expensive car’s company name and price.**Expected Output:**![pandas_printing_most_costly_car_name.webp](attachment:pandas_printing_most_costly_car_name.webp)<jupyter_code>import numpy as np
df[['company','price']][df['price'] == np.amax(df['price'])]<jupyter_output><empty_output><jupyter_text>Exercise 4:**Print All Toyota Cars details****Expected Output:**![pandas_printing_all_toyota_car_data.webp](attachment:pandas_printing_all_toyota_car_data.webp)<jupyter_code>df[df['company']=='toyota']<jupyter_output><empty_output><jupyter_text>Exercise 5:Count total cars per company**Expected Outcome:**![pandas_count_total_cars_per_company.webp](attachment:pandas_count_total_cars_per_company.webp)<jupyter_code>df['company'].value_counts()<jupyter_output><empty_output><jupyter_text>Exercise 6:Find each company’s Higesht price car**Expected Outcome:**![pandas_printing_each_companys_higesht_price_car.webp](attachment:pandas_printing_each_companys_higesht_price_car.webp)<jupyter_code>import numpy as np
df[['company','price']].groupby(['company']).max()<jupyter_output><empty_output><jupyter_text>Exercise 7:Find the average mileage of each car making company**Expected Output:**![pandas_printing_average_mileage_of_each_car_making_company.webp](attachment:pandas_printing_average_mileage_of_each_car_making_company.webp)<jupyter_code>import statistics as st
df[['company','average-mileage']].groupby(['company']).mean()<jupyter_output><empty_output><jupyter_text>Exercise 8:Sort all cars by Price column**Expected Output:**![pandas_sort_all_cars_by_price_column.webp](attachment:pandas_sort_all_cars_by_price_column.webp)<jupyter_code>df.sort_values(by = 'price',ascending = False)<jupyter_output><empty_output><jupyter_text>Exercise 9:Concatenate two data frames using the following conditionsCreate two data frames using the following two dictionaries.```pythonGermanCars = {'Company': ['Ford', 'Mercedes', 'BMV', 'Audi'], 'Price': [23845, 171995, 135925 , 71400]}japaneseCars = {'Company': ['Toyota', 'Honda', 'Nissan', 'Mitsubishi '], 'Price': [29995, 23600, 61500 , 58900]}```**Expected Output:**![pandas_concatenate_two_data_frames_and_create_key_for_each_data_frame.webp](attachment:pandas_concatenate_two_data_frames_and_create_key_for_each_data_frame.webp)<jupyter_code>GermanCars= {'Company': ['Ford', 'Mercedes', 'BMV', 'Audi'], 'Price': [23845, 171995, 135925 , 71400]}
JapaneseCars = {'Company': ['Toyota', 'Honda', 'Nissan', 'Mitsubishi '], 'Price': [29995, 23600, 61500 , 58900]}

display(GermanCars)
## Création et concaténation des dataframes

Germany = pd.DataFrame(GermanCars)
Japan = pd.DataFrame(JapaneseCars)

display(Germany)
#print('df G:\n',Germany)

#print('df J:\n',Japan)

df_L = [Germany, Japan]
  
df_c= pd.concat(df_L,keys=['German','Japan'])
display(df_c)<jupyter_output><empty_output><jupyter_text>Exercise 10:**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.```pythonCar_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:**![merge_two_data_frames_and_append_new_data_frame_as_new-column.webp](attachment:merge_two_data_frames_and_append_new_data_frame_as_new-column.webp)<jupyter_code>Car_Price = {'Company': ['Toyota', 'Honda', 'BMV', 'Audi'], 'Price': [23845, 17995, 135925 , 71400]}
car_Horsepower = {'Company': ['Toyota', 'Honda', 'BMV', 'Audi'], 'horsepower': [141, 80, 182 , 160]}
df_P = pd.DataFrame(Car_Price)
df_H = pd.DataFrame(car_Horsepower)
df_P.merge(df_H)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13428370292150651, 'fraction_numerical': 0.03396691305878212, 'mean_word_length': 7.248185776487663, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '573246', 'license': 'MIT', 'n_tokens_mistral': 2180, 'n_tokens_neox': 1984, 'n_words': 374, 'path': 'exercices/part3.ipynb', 'repo_name': 'AbdelwahabHassan/python-bootcamp', 'size': '5682'}