2021年3月6日星期六

nan shows up on my boxplot but there is no column labeled nan?

I started with:

print(NAsales_boxplotdf)  

and I got the following output:

              Genre  NA_Sales  0            Sports     41.49  1          Platform     29.08  2            Racing     15.85  3            Sports     15.75  4      Role-Playing     11.27  ...             ...       ...  16594       Shooter      0.01  16595        Racing      0.00  16596        Puzzle      0.00  16597      Platform      0.01  16598           NaN       NaN    [16599 rows x 2 columns]  

I then pivoted the the dataframe as follows:

NAsales_boxplotpivot = NAsales_boxplotdf.pivot(values = 'NA_Sales', columns = 'Genre')  

to get:

Genre  NaN  Action  Adventure  Fighting  Misc  Platform  Puzzle  Racing  \  0      NaN     NaN        NaN       NaN   NaN       NaN     NaN     NaN     1      NaN     NaN        NaN       NaN   NaN     29.08     NaN     NaN     2      NaN     NaN        NaN       NaN   NaN       NaN     NaN   15.85     3      NaN     NaN        NaN       NaN   NaN       NaN     NaN     NaN     4      NaN     NaN        NaN       NaN   NaN       NaN     NaN     NaN     ...    ...     ...        ...       ...   ...       ...     ...     ...     16594  NaN     NaN        NaN       NaN   NaN       NaN     NaN     NaN     16595  NaN     NaN        NaN       NaN   NaN       NaN     NaN    0.00     16596  NaN     NaN        NaN       NaN   NaN       NaN     0.0     NaN     16597  NaN     NaN        NaN       NaN   NaN      0.01     NaN     NaN     16598  NaN     NaN        NaN       NaN   NaN       NaN     NaN     NaN       Genre  Role-Playing  Shooter  Simulation  Sports  Strategy    0               NaN      NaN         NaN   41.49       NaN    1               NaN      NaN         NaN     NaN       NaN    2               NaN      NaN         NaN     NaN       NaN    3               NaN      NaN         NaN   15.75       NaN    4             11.27      NaN         NaN     NaN       NaN    ...             ...      ...         ...     ...       ...    16594           NaN     0.01         NaN     NaN       NaN    16595           NaN      NaN         NaN     NaN       NaN    16596           NaN      NaN         NaN     NaN       NaN    16597           NaN      NaN         NaN     NaN       NaN    16598           NaN      NaN         NaN     NaN       NaN      [16599 rows x 13 columns]  

I dropped the NaN column using:

NAsales_boxplotpivot[NAsales_boxplotpivot.columns.dropna()]  

to get this and then I put put it in a boxplot using:

NAsales_boxplotpivot.plot(kind='box', rot = 90, figsize = (20,10), showfliers = False)  

to get this.

https://stackoverflow.com/questions/66512206/nan-shows-up-on-my-boxplot-but-there-is-no-column-labeled-nan March 07, 2021 at 08:53AM

没有评论:

发表评论