Issue
I want to visualize the data types of my dataset as a part of exploratory data analysis and I have this data.
In [1]: df_planet = pd.DataFrame({'mass': [0.330, 4.87 , 5.97],
'radius': [2439.7, 6051.8, 6378.1],
'planet': ['Mercury', 'Venus', 'Earth']})
In [2]: df_planet.dtypes
Out[2]: mass float64
radius float64
planet object
dtype: object
How can I create a pie chart for the datatypes of df_planet
(i.e. 66.67% float64 and 33.33% object)?
I tried the following code but it throws an error:
In [3]: plt.pie(df_planet.dtypes, autopct='%.0f%%')
Out[3]: TypeError: float() argument must be a string or a number, not 'numpy.dtype[float64]'
Solution
You need to count the data types.
import pandas as pd
import matplotlib.pyplot as plt
df_planet = pd.DataFrame({'mass': [0.330, 4.87 , 5.97],
'radius': [2439.7, 6051.8, 6378.1],
'planet': ['Mercury', 'Venus', 'Earth']})
plt.pie(df_planet.dtypes.value_counts(),autopct='%.0f%%')
plt.show()
Answered By - norie
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.