<jupyter_start><jupyter_text>Merging Data avec Pandas Dans la science de données on a souvent besoin de fusionner des tableaux. On peut le faire avec la fonction `merge()` qui prend comme paramètres deux `DataFrames` ainsi que les colonnes avec lesquelles réaliser les jointures. Cette méthode est très similaire à SQL sur le principe 🔭  Importer pandas et les dataset `user_device.csv`, `user_usage.csv` et `android_devices.csv`<jupyter_code>import pandas as pd
user_device = pd.read_csv('data/user_device.csv')
user_usage = pd.read_csv('data/user_usage.csv')
android_devices = pd.read_csv('data/android_devices.csv'); android_devices.head()<jupyter_output><empty_output><jupyter_text>Importer les dataset & renommer la colonne `Branding` du dataset `android_devices.csv`<jupyter_code>android_devices.rename(columns={"Retail Branding": "Branding"})<jupyter_output><empty_output><jupyter_text>Afficher les dataset<jupyter_code>user_device.head()
user_usage.head()
android_devices.head()<jupyter_output><empty_output><jupyter_text>Votre premier merge<jupyter_code>merge = pd.merge(user_usage,user_device[['use_id','platform','device']],on='use_id', how='inner')<jupyter_output><empty_output><jupyter_text>Afficher la `shape` de vos dataset ainsi que celle du dataset de sortie Que remarquez vous ?<jupyter_code>user_usage.shape 
user_device.shape
merge.shape<jupyter_output><empty_output><jupyter_text>Afficher via `value_counts` les `use_id` présent dans le nouveau dataset ainsi que ceux non présent<jupyter_code>user_usage['use_id'].isin(user_device['use_id']).value_counts()<jupyter_output><empty_output><jupyter_text>Le left mergeAfficher la `shape` du dataset `user_usage`, celle du dataset de sortie ainsi que les valeurs manquantes.<jupyter_code>left_merge = pd.merge(user_usage,user_device[['use_id','platform','device']],on='use_id', how='left')
print('user_usage dimensions: ' + str(user_usage.shape))
print('result dimensions: ' + str(left_merge.shape))
print('There are missing '+ str(left_merge['device'].isna().sum()) + ' values in the result.')<jupyter_output>user_usage dimensions: (240, 4)
result dimensions: (240, 6)
There are missing 81 values in the result.<jupyter_text>Afficher votre dataset<jupyter_code>left_merge.head()<jupyter_output><empty_output><jupyter_text>Le right mergeAfficher la `shape` du dataset `user_device`, celle du dataset de sortie ainsi que les valeurs manquantes des colonnes `monthly_mb` et `platform`.<jupyter_code>right_merge = pd.merge(user_usage,user_device[['use_id','platform','device']],on='use_id', how='right')
print('user_device dimensions: ' + str(user_device.shape))
print('result dimensions: ' + str(right_merge.shape))
print('There are missing '+ str(right_merge['device'].isna().sum()) + ' values in the result.')<jupyter_output>user_device dimensions: (272, 6)
result dimensions: (272, 6)
There are missing 0 values in the result.<jupyter_text>Le outer merge exampleAfficher les valeurs unique de `use_id` des datasets `user_device` & `user_usage`, celle du dataset de sortie ainsi que les valeurs no manquantes.<jupyter_code>outer_merge = pd.merge(user_usage,user_device[['use_id','platform','device']],on='use_id', how='outer')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12387457311393978, 'fraction_numerical': 0.0058987891959018934, 'mean_word_length': 9.100313479623825, 'pattern_counts': {'":': 1, '<': 39, '<?xml version=': 0, '>': 39, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '446584', 'license': 'MIT', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1074, 'n_words': 249, 'path': '3 - pandas/exo/PandasMerge.ipynb', 'repo_name': 'JbDumaine/PythonEDA', 'size': '3221'}