<jupyter_start><jupyter_text>MPG Cars  Introduction:The following exercise utilizes data from [UC Irvine Machine Learning Repository](https://archive.ics.uci.edu/ml/datasets/Auto+MPG) Step 1. Import the necessary libraries<jupyter_code>import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>Step 2. Import the first dataset [cars1](https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/05_Merge/Auto_MPG/cars1.csv) and [cars2](https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/05_Merge/Auto_MPG/cars2.csv).       Step 3. Assign each to a variable called cars1 and cars2<jupyter_code>url1 = 'https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/05_Merge/Auto_MPG/cars1.csv'
url2 = 'https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/05_Merge/Auto_MPG/cars2.csv'
cars1 = pd.read_csv(url1)
cars2 = pd.read_csv(url2)
cars2.head()<jupyter_output><empty_output><jupyter_text>Step 4. Oops, it seems our first dataset has some unnamed blank columns, fix cars1<jupyter_code>cars1.head()
cars1 = cars1.loc[:, 'mpg': 'car']
cars1.head()<jupyter_output><empty_output><jupyter_text>Step 5. What is the number of observations in each dataset?<jupyter_code>print(cars1.shape)
print(cars2.shape)
# 都是 9 columns，可以attach<jupyter_output>(198, 9)
(200, 9)<jupyter_text>Step 6. Join cars1 and cars2 into a single DataFrame called cars<jupyter_code>cars = pd.concat([cars1, cars2], axis = 0)
print(cars.head())
print(cars.shape)<jupyter_output>mpg  cylinders  displacement horsepower  weight  acceleration  model  \
0  18.0          8           307        130    3504          12.0     70   
1  15.0          8           350        165    3693          11.5     70   
2  18.0          8           318        150    3436          11.0     70   
3  16.0          8           304        150    3433          12.0     70   
4  17.0          8           302        140    3449          10.5     70   

   origin                        car  
0       1  chevrolet chevelle malibu  
1       1          buick skylark 320  
2       1         plymouth satellite  
3       1              amc rebel sst  
4       1                ford torino  
(398, 9)<jupyter_text>Step 7. Oops, there is a column missing, called owners. Create a random number Series from 15,000 to 73,000.<jupyter_code># np.random.randint?
owners = np.random.randint(15000, 73000, size = cars.shape[0])
owners = pd.Series(owners).reset_index(drop=True)<jupyter_output><empty_output><jupyter_text>Step 8. Add the column owners to cars<jupyter_code>cars.head()
cars.shape
cars.reset_index(drop=True, inplace = True)
cars = pd.concat([cars, owners], axis = 1)
cars.rename(columns = {cars.columns[-1]: 'owners'}, inplace = True)
cars.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10085836909871244, 'fraction_numerical': 0.06866952789699571, 'mean_word_length': 2.9843304843304845, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 5, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '44776', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1093, 'n_tokens_neox': 965, 'n_words': 227, 'path': '05_Merge/Auto_MPG/Exercises05_MergeAuto_MPG.ipynb', 'repo_name': 'gabrielgege/pandas_exercises', 'size': '2796'}