본문 바로가기
Python

[Python] Pandas Course on Kaggle - 5

by llHoYall 2022. 1. 21.

This is the solution of pandas course (Data Types and Missing Values) on Kaggle site.

1. Get Data Type of Column

dtype = reviews.points.dtype
# or
dtype = reviews["points"].dtype

2. Change Data Type of Column

point_strings = reviews.points.astype(str)
# or
point_strings = reviews.points.astype('str')
# or
point_strings = reviews["points"].astype(str)
# or
point_strings = reviews["points"].astype('str')

3. Count the null Fields in Column

n_missing_prices = reviews.price.isnull().sum()
# or
n_missing_prices = reviews["price"].isnull().sum()
# or
n_missing_prices = pd.isnull(reviews.price).sum()
# or
n_missing_prices = pd.isnull(reviews["price"]).sum()

4. Fill null Fields in Column

reviews_per_region = reviews.region_1.fillna('Unknown')
                                     .value_counts()
                                     .sort_values(ascending=False)
# or
reviews_per_region = reviews["region_1"].fillna('Unknown')
                                        .value_counts()
                                        .sort_values(ascending=False)

'Python' 카테고리의 다른 글

[Python] Usage of .env  (0) 2022.04.23
[Python] Pandas Course on Kaggle - 6  (0) 2022.01.22
[Python] Pandas Course on Kaggle - 4  (0) 2022.01.20
[Python] Pandas Course on Kaggle - 3  (0) 2022.01.19
[Python] Pandas Course on Kaggle - 2  (0) 2022.01.17

댓글