Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count data types in pandas dataframe

Tags:

python

pandas

I have pandas.DataFrame with too much number of columns.

I call:

In [2]: X.dtypes

Out[2]: VAR_0001     object
        VAR_0002      int64
                 ...   
        VAR_5000      int64
        VAR_5001      int64

And I can't understand what types of data I have between VAR_0002 and VAR_5000

It's can be int64, int8, float64 and so on. I see in this blog native type of pandas.DataFrame but I think this is wrong information. How can I get this?

And other question. When I work on PC (Windows) and call this:

In [3]: X.dtypes[X.dtypes.map(lambda x: x=='bool')]

I get several columns with this type of data. But when I use this command on Mac, I get nothing. WAT?

like image 443
Gilaztdinov Rustam Avatar asked Sep 01 '15 17:09

Gilaztdinov Rustam


People also ask

How do I count data types in pandas?

get_dtype_counts() function returns the counts of dtypes in the given object. It returns a pandas series object containing the counts of all data types present in the pandas object. It works with pandas series as well as dataframe.

How do you count elements in pandas?

Pandas DataFrame count() MethodThe count() method counts the number of not empty values for each row, or column if you specify the axis parameter as axis='columns' , and returns a Series object with the result for each row (or column).

What does Value_counts () do in pandas?

Return a Series containing counts of unique values. The resulting object will be in descending order so that the first element is the most frequently-occurring element.


1 Answers

To answer your first question do the following:

df.dtypes.value_counts()

Example:

In [4]:

df = pd.DataFrame({'a':[0], 'b':['asds'], 'c':[0]})
df.dtypes
Out[4]:
a     int64
b    object
c     int64
dtype: object
In [5]:

df.dtypes.value_counts()
Out[5]:
int64     2
object    1
dtype: int64
like image 68
EdChum Avatar answered Oct 09 '22 01:10

EdChum