0% found this document useful (0 votes)
144 views1 page

Data Merge - Hands-On 2

This Python code first creates two series containing name IDs ranging from 101 to 110 and corresponding names as strings. It then combines these into a DataFrame and merges it with another DataFrame of transactions to join them on the name ID field. The merged DataFrame is then printed, outputting a table with name IDs, names, and products purchased.

Uploaded by

Rishika Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views1 page

Data Merge - Hands-On 2

This Python code first creates two series containing name IDs ranging from 101 to 110 and corresponding names as strings. It then combines these into a DataFrame and merges it with another DataFrame of transactions to join them on the name ID field. The merged DataFrame is then printed, outputting a table with name IDs, names, and products purchased.

Uploaded by

Rishika Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import pandas as pd

import numpy as np

nameid = pd.Series(range(101,111))

name = pd.Series(['person' + str(i) for i in range(1,11)])

master = pd.DataFrame()

master['nameid'] = nameid

master['name'] = name

transaction = pd.DataFrame({'nameid':[108,108,108,103],'product':
['iPhone','Nokia','Micromax','Vivo']})

mdf = pd.merge(master,transaction,on='nameid')

print(mdf)

You might also like