0% found this document useful (0 votes)
220 views2 pages

Data Merge - Hands-On 1

This document contains code to create two Pandas DataFrames (df_AA and df_B) with student data like height, weight, and gender. It then concatenates the two DataFrames into a single DataFrame called df and prints it. The first DataFrame (df_AA) contains hardcoded student data while the second (df_B) generates random normal distributed student data.

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)
220 views2 pages

Data Merge - Hands-On 1

This document contains code to create two Pandas DataFrames (df_AA and df_B) with student data like height, weight, and gender. It then concatenates the two DataFrames into a single DataFrame called df and prints it. The first DataFrame (df_AA) contains hardcoded student data while the second (df_B) generates random normal distributed student data.

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/ 2

import pandas as pd

import numpy as np

height_A = pd.Series([176.2,158.4,167.6,156.2,161.4])

height_A.index = ['s1','s2','s3','s4','s5']

weights_A = pd.Series([85.1,90.2,76.8,80.4,78.9])

weights_A.index = ['s1','s2','s3','s4','s5']

df_A = pd.DataFrame()

df_A['Student_height'] = height_A

df_A['Student_weight'] = weights_A

df_A['Gender'] = ['M','F','M','M','F']

s = pd.Series([165.4,82.7,'F'],index =
['Student_height','Student_weight','Gender'],name='s6')

df_AA = df_A.append(s)

print(df_AA)

#TASK - 2

my_mean = 170.0

my_std = 25.0

np.random.seed(100)

heights_B = pd.Series(np.random.normal(loc = my_mean,scale=my_std,size = 5))

heights_B.index = ['s1','s2','s3','s4','s5']

my_mean1 = 75.0

my_std1 = 12.0

np.random.seed(100)

weights_B = pd.Series(np.random.normal(loc = my_mean1,scale=my_std1,size = 5))

weights_B.index = ['s1','s2','s3','s4','s5']

df_B = pd.DataFrame()

df_B['Student_height'] = heights_B

df_B['Student_weight'] = weights_B

df_B.index=['s7','s8','s9','s10','s11']

df_B['Gender'] = ['F','M','F','F','M']
df = pd.concat([df_AA,df_B])

print(df)

You might also like