<jupyter_start><jupyter_text>Many-to-many data mergeThe final merging scenario occurs when both DataFrames do not have unique keys for a merge. What happens here is that for each duplicated key, every pairwise combination will be created.Two example DataFrames that share common key values have been pre-loaded: df1 and df2. Another DataFrame df3, which is the result of df1 merged with df2, has been pre-loaded. All three DataFrames have been printed - look at the output and notice how pairwise combinations have been created. This example is to help you develop your intuition for many-to-many merges.Here, you'll work with the site and visited DataFrames from before, and a new survey DataFrame. Your task is to merge site and visited as you did in the earlier exercises. You will then merge this merged DataFrame with survey.Begin by exploring the site, visited, and survey DataFrames in the IPython Shell. Instructions- Merge the site and visited DataFrames on the 'name' column of site and 'site' column of visited, exactly as you did in the previous two exercises. Save the result as m2m.- Merge the m2m and survey DataFrames on the 'ident' column of m2m and 'taken' column of survey.- Hit 'Submit Answer' to print the first 20 lines of the merged DataFrame!<jupyter_code>import pandas as pd
survey=pd.read_csv('survey.txt')

survey
site=pd.read_csv('site.csv')
print(site)

visited=pd.read_csv('visited.csv')
print(visited)

# Merge the DataFrames: m2o
m2o = pd.merge(left= site, right=visited, left_on='name', right_on='site')

# Print m2o
print(m2o)
# Merge site and visited: m2m
m2m = pd.merge(left=site, right=visited , left_on='name', right_on='site')

# Merge m2m and survey: m2m
m2m = pd.merge(left=m2m, right=survey, left_on='ident', right_on='taken')

# Print the first 20 lines of m2m
print(survey)<jupyter_output>taken person  quant    reading
0     619   dyer    rad       9.82
1     619   dyer    sal       0.13
2     622   dyer    rad       7.80
3     622   dyer    sal       0.09
4     734     pb    rad       8.41
5     734   lake    sal       0.05
6     734     pb   temp     -21.50
7     735     pb    rad       7.22
8     735    NaN    sal       0.06
9     735    NaN   temp     -26.00
10    751     pb    rad       4.35
11    751     pb   temp     -18.50
12    751   lake    sal       0.10
13    752   lake    rad       2.19
14    752   lake    sal       0.09
15    752   lake   temp     -16.00
16    752    roe    sal       1.60
17    837   lake    rad       1.46
18    837   lake    sal       0.21
19    837    roe    sal      22.50
20    844    roe     ad      11.25
{'fraction_non_alphanumeric': 0.061200923787528866, 'fraction_numerical': 0.07197844495765973, 'mean_word_length': 2.4885906040268457, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '452114', 'license': 'MIT', 'n_tokens_mistral': 913, 'n_tokens_neox': 813, 'n_words': 362, 'path': 'cleaning data in python/Combining data for analysis/07. Many-to-many data merge.ipynb', 'repo_name': 'nazmus-shakib-mist-ipe02/Importing-Cleaning-Data-with-Python', 'size': '2598'}