0

So I'm new to pandas and this is my first notebook. I needed to join some columns of my dataframe and after that, I wanted to separate the values so it would be better to visualize them.

to join the columns I used df['Q7'] = df[['Q7_Part_1', 'Q7_Part_2', 'Q7_Part_3', 'Q7_Part_4', 'Q7_Part_5','Q7_Part_6','Q7_OTHER']].apply(lambda x : '_'.join(x.dropna().astype(str)), axis=1) and it did well, but i still needed to separate the values and for that i used explode() like: df.Q7 = df.Q7.str.split('_').explode('Q7') and that gave me some empty cells on the dataframe like: Dataframe and when i try to visualize the values they just come in empty like: sum of empty cells

What could I do to not show these empty cells on the viz?

Edit 1: By the way, they not appear as null or NaN cells when I do: df.isnull().sum() or df.isna().sum()

  • You could paste the print of your dataframe here, so people can copy and try to reproduce your need. – igorkf Mar 03 '21 at 18:58
  • See [How to make good, reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and provide sample input and expected output to make a [mcve]. It would also help to [edit] your question to clarify: Are you asking how to prevent the empty cells, or how to exclude them from the plot? – G. Anderson Mar 03 '21 at 18:59

1 Answers1

0
c = ['Q7_Part_1', 'Q7_Part_2', 'Q7_Part_3', 'Q7_Part_4', \
'Q7_Part_5','Q7_Part_6','Q7_OTHER']

df['Q7'] = df[c].apply(lambda x : '_'.join(x.astype(str)), axis=1)

I am not able to replicate your issue but my best guess is if you will do the above the dimension of the list will remain intact and you will get string 'nan' values instead of empty strings.

AnBan
  • 1