许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  【Python | Kaggle】机器学习系列之Pandas基础练习题(五)

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

阅读数 8
点赞 0
article_banner

前言

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

Introduction

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

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

reviews = 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

运行结果:
image.png

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')

运行结果:
image.png

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()

运行结果:
image.png

   其余参考Demo:

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

# or
    
missing_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)

运行结果:
image.png

结语

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

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

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

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

谢谢支持 ❤️


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空