-1

i am trying to check any loss of data in categorical columns (such as data for an entire category) after data cleansing. i have 2 series that contains unique values of each categorical column in the dataframes.

Before Data Cleansing

  • dataframe1.nunique()
Column 1 10
Column 2 20

After Data Cleansing

  • dataframe2.nunique()
Column 1 10
Column 2 15

Any idea how to get a table in the following format for better presentation ? Both dataframe has same columns, but not same row count.

Column 1 10 10
Column 2 20 15
Braiam
  • 1
  • 11
  • 47
  • 78
bStk83
  • 19
  • 5
  • Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – Anurag Dabas May 30 '21 at 06:15
  • use `df1.merge(df2,on='Column Name',suffixes=('_before','_after'))` – Anurag Dabas May 30 '21 at 06:15
  • ok..i have updated my question, dataframe2.nunique() gives us series, where first column contains column names and second column contains unique values. – bStk83 May 30 '21 at 06:21

1 Answers1

0

You can use concat() method:

df=pd.concat([df1,df2],axis=1)
df.columns=['Unique Value Count_before','Unique Value Count_after']

OR

via to_frame() and merge() method

df=df1.to_frame().merge(df2.to_frame(),on='Column Name',suffixes=('_before','_after'))

Output:

Column Name Unique Value Count_Before   Unique Value Count_After
Column 1    10                          10
Column 2    20                          15
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41