Write a python program to create the dataframe to perform binary functions on it
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:
Comments
Leave a comment