Open hemza-G opened 10 months ago
import pandas as pd
data = {'Column1': [123, 200, 100, 120, 130]} index = pd.MultiIndex.from_tuples([('Abc', 123), ('A', 1), ('A', 2), ('B', 1), ('B', 2)], names=['Index1', 'Index2']) df = pd.DataFrame(data, index=index)
df['Total'] = df.groupby(level=0)['Column1'].transform('sum') df = df.reset_index() df = df.set_index(['Index1', 'Total'])
print(df)
import matplotlib.pyplot as plt import pandas as pd
Assuming df1 and df2 are your two dataframes
df1 = pd.DataFrame({'Column1': [1, 2, 3], 'Column2': ['A', 'B', 'C']}) df2 = pd.DataFrame({'Column3': [4, 5, 6], 'Column4': ['X', 'Y', 'Z']})
Plotting the first table
fig, axs = plt.subplots(1, 2, figsize=(10, 4))
Displaying the first table
axs[0].axis('tight') axs[0].axis('off') axs[0].table(cellText=df1.values, colLabels=df1.columns, cellLoc = 'center', loc='center')
Displaying the second table
axs[1].axis('tight') axs[1].axis('off') axs[1].table(cellText=df2.values, colLabels=df2.columns, cellLoc = 'center', loc='center')
Adjust layout
plt.show()