I have 2 data frames with 25 columns. I am trying to get the distributions for each column in both data frames, for a comparative study.
I do something like this:
count1=df1[col].value_counts().reset_index()
count2=df2[col].value_counts().reset_index()
merged=count1.merge(count2,how='outer',on='index')
Some columns have a list instead of string. I want to convert them to string and then do the above steps.
df1[col+'_str']=df1[col].str.join(' ')
df2[col+'_str']=df2[col].str.join(' ')
Now, the problem is that I don't know which columns will have list. Is there a way to find if the contents of a column has list/string?
I tried this:
if((type(df1[col].iloc[0])=='list' )):
But, some of those columns without a value in 0th row, will bypass this test!
How can I find out the type of contents in a dataframe column?
I referred to this SO question, but couldn't use much: SO question