Tutorial by Examples

Types of columns can be checked by .dtypes atrribute of DataFrames. In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': [True, False, True]}) In [2]: df Out[2]: A B C 0 1 1.0 True 1 2 2.0 False 2 3 3.0 True In [3]: df.dtypes Out[3]: A int64 ...
astype() method changes the dtype of a Series and returns a new Series. In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['1.1.2010', '2.1.2011', '3.1.2011'], 'D': ['1 days', '2 days', '3 days'], ...
select_dtypes method can be used to select columns based on dtype. In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['a', 'b', 'c'], 'D': [True, False, True]}) In [2]: df Out[2]: A B C D 0 1 1.0 a True 1 2 2.0 b False 2...
get_dtype_counts method can be used to see a breakdown of dtypes. In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['a', 'b', 'c'], 'D': [True, False, True]}) In [2]: df.get_dtype_counts() Out[2]: bool 1 float64 1 int64 1 obje...

Page 1 of 1