Answer to Question #145507 in Python for Dharmarajan

Question #145507

Write a python program to create the dataframe to perform binary functions on it


1
Expert's answer
2020-11-20T10:12:22-0500
import pandas as pd 
 
#THE LISTS ARE IINITIALISED AS DATA 1 AND DATA 2
data1 = ([[1,2,3,4,5],[10,11,12,13,14]])
data2 = ([[2,3,4,5,6]])
 
#DATA FRAME FOR LIST 1 
df_1= pd.DataFrame(data1)
print("Data frame1 is : ")  #PRINT THE DATA FRAME
print(df_1)
print('')

#DATA FRAME FOR LIST 2
df_2= pd.DataFrame(data2)
print("Data frame2 is : ") #PRINT THE DATA FRAME
print(df_2)
print('')


print("Addition of two data frames is :")
print(df_1.add(df_2))  #ADDITION OF THE DATA FRAME
print('')

print("Subtraction of two data frames is :")
sub = df_1 - df_2 #Subtraction of two data frames
print(sub)
print('')

print("Multiplication of two data frames is :")
print(df_1.mul(df_2,)) #Multiplication of two data frames
print('')

print("Division of two data frames is :")
print(df_1.div(df_2,))  #DIVISION of two data frames
print('')

print("Modulus of two data frames is :")
print(df_1.mod(df_2,))  #MODULUS of two data frames
print('')

print("We can fill values for NaN using fill_value arguments.")
print("Addition of two data frames using fill_value arguments is:")
print(df_1.add(df_2, fill_value = 0)) #FILLING VALUES FOR NaN as 0 
# We can use any suitable value as fill_value for performing 
#binary functions.


OUTPUT:


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS