【Python|Kaggle】机器学习系列之Pandas基础练习题(五)

编程入门 行业动态 更新时间:2024-10-12 22:33:20

【Python|Kaggle】机器学习系列之Pandas基础<a href=https://www.elefans.com/category/jswz/34/1768594.html style=练习题(五)"/>

【Python|Kaggle】机器学习系列之Pandas基础练习题(五)

前言

Hello!小伙伴!
非常感谢您阅读海轰的文章,倘若文中有错误的地方,欢迎您指出~
 
自我介绍 ଘ(੭ˊᵕˋ)੭
昵称:海轰
标签:程序猿|C++选手|学生
简介:因C语言结识编程,随后转入计算机专业,有幸拿过一些国奖、省奖…已保研。目前正在学习C++/Linux/Python
学习经验:扎实基础 + 多做笔记 + 多敲代码 + 多思考 + 学好英语!
 
初学Python 小白阶段
文章仅作为自己的学习笔记 用于知识体系建立以及复习
题不在多 学一题 懂一题
知其然 知其所以然!

往期推荐

【Python|Kaggle】机器学习系列之Pandas基础练习题(一)

【Python|Kaggle】机器学习系列之Pandas基础练习题(二)

【Python|Kaggle】机器学习系列之Pandas基础练习题(三)

【Python|Kaggle】机器学习系列之Pandas基础练习题(四)

Introduction

Run the following cell to load your data and some utility functions.

运行下面代码 导入此次练习需要的数据、库…

import pandas as pdreviews = pd.read_csv("../input/wine-reviews/winemag-data-130k-v2.csv", index_col=0)from learntools.core import binder; binder.bind(globals())
from learntools.pandas.data_types_and_missing_data import *
print("Setup complete.")

Exercises

1.

题目

What is the data type of the points column in the dataset?

解答

题目意思:

查询points的类型

dtype = reviews.points.dtype

运行结果:

2.

题目

Create a Series from entries in the points column, but convert the entries to strings. Hint: strings are str in native Python.

解答

题目意思:

将points列中的数据类型转换为string

point_strings = reviews.points.astype('str')

运行结果:

3.

题目

Sometimes the price column is null. How many reviews in the dataset are missing a price?

解答

题目意思:

统计price列中nan的数量

n_missing_prices = pd.isnull(reviews.price).sum()

运行结果:

其余参考Demo:

n_missing_prices = reviews.price.isnull().sum()# ormissing_price_reviews = reviews[reviews.price.isnull()]
n_missing_prices = len(missing_price_reviews)

4.

题目

What are the most common wine-producing regions? Create a Series counting the number of times each value occurs in the region_1 field. This field is often missing data, so replace missing values with Unknown. Sort in descending order. Your output should look something like this:

Unknown                    21247
Napa Valley                 4480...  
Bardolino Superiore            1
Primitivo del Tarantino        1
Name: region_1, Length: 1230, dtype: int64

解答

题目意思:

首先需要将region_1中的空值用“unknown”填充
然后统计每一个地方的频率

reviews_per_region = reviews.region_1.fillna("Unknown").value_counts().sort_values(ascending=False)

运行结果:

结语

文章仅作为学习笔记,记录从0到1的一个过程

希望对您有所帮助,如有错误欢迎小伙伴指正~

我是 海轰ଘ(੭ˊᵕˋ)੭

如果您觉得写得可以的话,请点个赞吧

谢谢支持 ❤️

更多推荐

【Python|Kaggle】机器学习系列之Pandas基础练习题(五)

本文发布于:2023-06-29 15:57:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/947148.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:练习题   机器   基础   系列之   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!