简体   繁体   中英

How to compare 3 DataFrame in 1 DataFrame Pandas

I have 3 datasets df1 , df2 , df3 and each of these have number of rows and number of columns and I would like to have 1 DataFrame which will show these numbers, for example:

在此处输入图像描述

How can I create DataFrame like above?

You can use the following line of code

pd.DataFrame({'df1': df1.shape, 'df2': df2.shape, 'df3': df3.shape}, index=['rows', 'columns'])

Simple Example

import pandas as pd
import seaborn as sns

df1 = sns.load_dataset('iris')
df2 = sns.load_dataset('titanic')
df3 = sns.load_dataset('mpg')

pd.DataFrame({'df1': df1.shape, 'df2': df2.shape, 'df3': df3.shape}, index=['rows', 'columns'])

#          df1  df2  df3
# rows     150  891  398
# columns    5   15    9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM