数据分析从零开始实战,Pandas读取HTML页面+数据处理解析

本文介绍了使用Pandas的read_html函数读取和处理HTML页面数据,详细讲解了如何处理列名、缺失数据(dropna和fillna函数),并提供数据爬取和简单的数据可视化的实战例子,例如分析2019富豪榜中各国人数、公司分布等。
摘要由CSDN通过智能技术生成

一 基本知识概要

1.利用Pandas检索HTML页面(read_html函数)

2.实战训练使用read_html函数直接获取页面数据

3.基本数据处理:表头处理、dropna和fillna详解

4.基本数据可视化分析案例

二 开始动手动脑

1.Pandas的read_html函数

这里我们要介绍的是Pandas里解析HTML页面的函数:read_html

查看源码后我们可以看出,该函数的参数比较多,下面我挑重点给大家解释几个。

(1)io(最关键参数)

源码注释

		A URL, a file-like object, or a raw string containing HTML. Note that
        lxml only accepts the http, ftp and file url protocols. If you have a
        URL that starts with ``'https'`` you might try removing the ``'s'``.
复制代码

我的理解

	数据地址(网页地址、包含HTML的文件地址或者字符串)。
	注意lxml只接受HTTP、FTP和文件URL协议。
	如果你有以“https”开头的URL,你可以尝试删除“s”再传入参数。
复制代码

(2)match

源码注释

		str or compiled regular expression, optional
        The set of tables containing text matching this regex or string will be
        returned. Unless the HTML is extremely simple you will probably need to
        pass a non-empty string here. Defaults to '.+' (match any non-empty
        string). The default value will return all tables contained on a page.
        This value is converted to a regular expression so that there is
        consistent behavior between Beautiful Soup and lxml.
复制代码

我的理解

	字符串或编译的正则表达式,可选
	包含与此正则表达式或字符串匹配的文本的一组表将返回。
	除非HTML非常简单,否则您可能需要在此处传递一个非空字符串。
	默认为“.+”(匹配任何非空字符串)。默认值将返回页面上包含的所有<table>标签包含的表格。
	该值将转换为正则表达式,以便Beautiful Soup和LXML之间一致。
复制代码

(3)flavor

源码注释

		flavor : str or None, container of strings
        The parsing engine to use. 'bs4' and 'html5lib' are synonymous with
        each other, they are both there for backwards compatibility. The
        default of ``None`` tries to use ``lxml`` to parse and if that fails it
        falls back on ``bs4`` + ``html5lib``.
复制代码

我的理解

	要使
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值