You can treat data frames like matrices and perform calculation.
Import the library:
import pandas as pd
Read the data frame:
# Create first DataFrame
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [3, 4, 7]})
# Create second DataFrame
df2 = pd.DataFrame({'A': [5, 6, 9], 'B': [7, 8, 8]})
# Read both dataframes
print('Dataframe 1:\\n', df1)
print('Dataframe 2:\\n', df2)
Output:
Dataframe 1:
A B
0 1 3
1 2 4
2 3 7
Dataframe 2:
A B
0 5 7
1 6 8
2 9 8
You can transpose a data frame like transposing a matrix
# Transpose the data frame
print('Dataframe 1:\\n', df1.T)
print('Dataframe 2:\\n', df2.T)
Output:
Dataframe 1:
0 1 2
A 1 2 3
B 3 4 7
Dataframe 2:
0 1 2
A 5 6 9
B 7 8 8
Perform element-wise multiplication:
# Perform element-wise multiplication
print("df1 * df2:\\n", df1 * df2)
Output:
df1 * df2:
A B
0 5 21
1 12 32
2 27 56