Any data science or data analytics project can be generally described with the following steps:

通常可以通过以下步骤来描述任何数据科学或数据分析项目:

  1. Acquiring a business understanding & defining the goal of a project
    获得业务理解并定义项目目标
  2. Getting data
    获取数据
  3. Preprocessing and exploring data
    预处理和探索数据
  4. Improving data, e.g., by feature engineering
    改善数据,例如通过特征工程
  5. Visualizing data
    可视化数据
  6. Building a model
    建立模型
  7. Deploying the model
    部署模型
  8. Scoring its performance
    对其表现进行评分

This time, I would like to bring your attention to the data cleaning and exploration phase since it’s a step which value is hard to measure, but the impact it brings is difficult to overestimate. Insights gained during this stage can affect all further work.

这次,我想提请您注意数据清理和探索阶段,因为这是一个难以衡量的步骤,但很难估量其带来的影响。 在此阶段获得的见解会影响所有进一步的工作。

There are multiple ways you can start exploratory data analysis with:

您可以通过多种方式开始探索性数据分析:

  1. Load data and preprocess it: clean it from unnecessary artifacts, deal with missing values. Make your dataset comfortable to work with.
    加载数据并进行预处理:清除不必要的工件,处理缺失值。 使数据集易于使用。
  2. Visualize as much data as possible using different kinds of plots & a pivot table.
    使用不同种类的绘图和数据透视表,可视化尽可能多的数据。

目的 (Purpose)

In this tutorial, I would like to show how to prepare your data with Python and explore it using a JavaScript library for data visualization. To get the most value out of exploration, I recommend using interactive visualizations since they make exploring your data faster and more comfortable.

在本教程中,我想展示如何使用Python 准备数据并使用JavaScript库进行数据可视化探索。 为了从探索中获得最大价值,我建议使用交互式可视化,因为它们可以使您更快,更舒适地浏览数据。

Hence, we will present data in an interactive pivot table and pivot charts.

因此,我们将在交互式数据透视表数据透视图中显示数据。

Hopefully, this approach will help you facilitate the data analysis and visualization process in Jupyter Notebook.

希望这种方法将帮助您促进Jupyter Notebook中的数据分析和可视化过程。

设置环境 (Set up your environment)

Run your Jupyter Notebook and let’s start. If Jupyter is not installed on your machine, choose the way to get it.

运行Jupyter Notebook,开始吧。 如果您的计算机上未安装Jupyter,请选择获取方式 。

获取数据 (Get your data)

Choosing the data set to work with is the number one step.

选择要使用的数据集是第一步。

If your data is already cleaned and ready to be visualized, jump to the Visualization section.

如果您的数据已被清理并准备可视化,请跳至“ 可视化”部分。

For demonstration purposes, I’ve chosen the data for the prediction of Bike Sharing Demand. It’s provided as data for the Kaggle’s competition.

出于演示目的,我选择了用于预测“ 自行车共享需求”的数据 。 作为Kaggle比赛数据提供。

本教程的导入 (Imports for this tutorial)

Classically, we will use the “pandas” library to read data into a dataframe.

传统上,我们将使用“ pandas”库将数据读入数据框。

Additionally, we will need json and IPython.display modules. The former will help us serialize/deserialize data and the latter — render HTML in the cells.

此外,我们将需要jsonIPython.display模块。 前者将帮助我们对数据进行序列化/反序列化,而后者将在单元格中呈现HTML。

Here’s the full code sample with imports we need:

这是我们需要导入的完整代码示例:

from IPython.display import HTMLimport jsonimport pandas as pd

读取数据 (Read data)

df = pd.read_csv('train.csv')

df = pd.read_csv('train.csv')

清理和预处理数据 (Clean & preprocess data)

Before starting data visualization, it’s a good practice to see what’s going on in the data.

在开始数据可视化之前,最好先查看数据中发生了什么。

df.head()

df.head()

df.info()

df.info()

First, we should check the percentage of missing values.

首先,我们应该检查缺失值的百分比。

missing_percentage = df.isnull().sum() * 100 / len(df)

missing_percentage = df.isnull().sum() * 100 / len(df)

There are a lot of strategies to follow when dealing with missing data. Let me mention the main ones:

处理丢失的数据时,有许多策略可以遵循。 让我提到主要的:

  1. Dropping missing values. The only reason to follow this approach is when you need to quickly remove all NaNs from the data.
    删除缺失值。 遵循这种方法的唯一原因是当您需要快速从数据中删除所有NaN时。
  2. Replacing NaNs with values. This is called imputation. A common decision is to replace missing values with zeros or with a mean value.

    用值替换NaN。 这称为归因 。 常见的决定是用零或平均值替换缺失值。

Luckily, we don’t have any missing values in the dataset. But if your data has, I suggest you look into a quick guide with the pros and cons of different imputation techniques.

幸运的是,我们在数据集中没有任何缺失值。 但是,如果您有数据,建议您快速了解各种插补技术的优缺点 。

管理要素数据类型 (Manage features data types)

Let’s convert the type of “datetime”’ column from object to datetime:

让我们将“ datetime”列的类型从对象转换为datetime:

df['datetime'] = pd.to_datetime(df['datetime'])

df['datetime'] = pd.to_datetime(df['datetime'])

Now we are able to engineer new features based on this column, for example:

现在,我们可以根据此专栏设计新功能,例如:

  • a day of the week
    一周中的一天
  • a month
    一个月
  • an hour
    一小时
df['weekday'] = df['datetime'].dt.dayofweekdf['hour'] = df['datetime'].dt.hourdf['month'] = df['datetime'].dt.month

These features can be used further to figure out trends in rent.

这些功能可以进一步用于确定租金趋势。

Next, let’s convert string types to categorical:

接下来,让我们将字符串类型转换为分类类型:

categories = ['season', 'workingday', 'weekday', 'hour', 'month', 'weather', 'holiday']for category in categories:    df[category] = df[category].astype('category')

Read more about when to use the categorical data type here.

在此处阅读有关何时使用分类数据类型的更多信息。

Now, let’s make values of categorical more meaningful by replacing numbers with their categorical equivalents:

现在,通过将数字替换为对应的类别,使分类的值更有意义:

df['season'] = df['season'].replace([1, 2, 3, 4], ['spring', 'summer', 'fall', 'winter'])df['holiday'] = df['holiday'].replace([0, 1],['No', 'Yes'])

By doing so, it will be easier for us to interpret data visualization later on. We won’t need to look up the meaning of a category each time we need it.

这样,以后我们将更容易解释数据可视化。 我们不需要每次都需要查找类别的含义。

使用数据透视表和图表可视化数据 (Visualize data with a pivot table and charts)

Now that you cleaned the data, let’s visualize it.

现在您已经清理了数据,让我们对其可视化。

The data visualization type depends on the question you are asking.

数据可视化类型取决于您要询问的问题。

In this tutorial, we’ll be using:

在本教程中,我们将使用:

  • a pivot table for tabular data visualization
    用于表格数据可视化的数据透视表
  • a bar chart
    条形图

为数据透视表准备数据 (Prepare data for the pivot table)

Before loading data to the pivot table, convert the dataframe to an array of JSON objects. For this, use the to_json() function from the json module.

在将数据加载到数据透视表之前,将数据帧转换为JSON对象数组。 为此,请使用json模块中的to_json()函数。

The records orientation is needed to make sure the data is aligned according to the format the pivot table requires.

需要records方向,以确保数据根据数据透视表所需的格式对齐。

json_data = df.to_json(orient=”records”)

json_data = df.to_json(orient=”records”)

创建数据透视表 (Create a pivot table)

Next, define a pivot table object and feed it with the data. Note that the data has to be deserialized using the loads() function that decodes JSON:

接下来,定义数据透视表对象并向其提供数据。 请注意,必须使用可解码JSON的loads()函数对数据进行反序列化:

pivot_table = {        "container": "#pivot-container",        "componentFolder": "https://cdn.flexmonster.com/",        "toolbar": True,        "report": {            "dataSource": {                "type": "json",                "data": json.loads(json_data)            },            "slice": {                "rows": [{                    "uniqueName": "weekday"                }],                "columns": [{                    "uniqueName": "[Measures]"                }],                "measures": [{                    "uniqueName": "count",                    "aggregation": "median"                }],                "sorting": {                    "column": {                        "type": "desc",                        "tuple": [],                        "measure": {                            "uniqueName": "count",                            "aggregation": "median"                        }                    }                }            }        }    }

In the above pivot table initialization, we specified a simple report that consists of a slice (a set of fields visible on the grid), data source, options, formats, etc. We also specified a container where the pivot table should be rendered. The container will be defined a bit later.

在上述数据透视表初始化中,我们指定了一个简单的报告,该报告由一个切片(网格上可见的一组字段),数据源,选项,格式等组成。我们还指定了一个应在其中呈现数据透视表的容器。 稍后将定义容器。

Plus, here we can add a mapping object to prettify the field captions or set their data types. Using this object eliminates the need in modifying the data source.

另外,在这里我们可以添加一个映射对象来美化字段标题或设置其数据类型。 使用此对象消除了修改数据源的需要。

Next, convert the pivot table object to a JSON-formatted string to be able to pass it for rendering in the HTML layout:

接下来,将数据透视表对象转换为JSON格式的字符串,以便能够将其传递以在HTML布局中呈现:

pivot_json_object = json.dumps(pivot_table)

pivot_json_object = json.dumps(pivot_table)

定义仪表板布局 (Define a dashboard layout)

Define a function that renders the pivot table in the cell:

定义一个在单元格中呈现数据透视表的函数:

In this function, we call HTML() from the IPython.display module — it will render the layout enclosed into a multi-line string.

在此函数中,我们从IPython.display模块调用HTML() - 它会 将布局呈现为多行字符串。

Next, let’s call this function and pass to it the pivot table previously encoded into JSON:

接下来,让我们调用此函数并将之前编码为JSON的数据透视表传递给它:

render_pivot_table(pivot_json_object)

render_pivot_table(pivot_json_object)

Likewise, you can create and render as many data visualization components as you need. For example, interactive pivot charts that visualize aggregated data:

同样,您可以根据需要创建和呈现任意数量的数据可视化组件 。 例如,可视化聚合数据的交互式数据透视图 :

下一步是什么 (What’s next)

Now that you embedded the pivot table into Jupyter, it’s time to start exploring your data:

现在,您已将数据透视表嵌入Jupyter中,是时候开始探索数据了:

  • drag and drop fields to rows, columns, and measures of the pivot table

    将字段拖放到数据透视表的行,列和度量

  • set Excel-like filtering

    设置类似Excel的过滤

  • highlight important values with conditional formatting

    使用条件格式突出显示重要的值

At any moment, you can save your results to a JSON or PDF/Excel/HTML report.

您随时可以将结果保存到JSONPDF / Excel / HTML报告中。

例子 (Examples)

Here is how you can try identifying trends on bikes usage depending on the day of the week:

您可以按照以下方式尝试确定自行车使用情况的趋势,具体取决于星期几:

You can also figure out if any weather conditions affect the number of rents by registered and unregistered users:

您还可以确定是否有任何天气情况影响注册和未注册用户的租金数量:

To dig deeper into the data, drill through aggregated values by double-clicking and see the raw records they are composed of:

要通过双击深入挖掘数据, 追溯汇总值,看看它们是由原始的记录:

Or simply switch to the pivot charts mode and give your data an even more comprehensible look:

或者,只需切换到数据透视图模式,即可使您的数据看起来更清晰:

汇集全部 (Bringing it all together)

By completing this tutorial, you learned a new way to interactively explore your multi-dimensional data in Jupyter Notebook using Python and the JavaScript data visualization library. I hope this will make your exploration process more insightful than before.

通过完成本教程,您学习了一种使用Python和JavaScript数据可视化库在Jupyter Notebook中交互式浏览多维数据的新方法。 我希望这将使您的探索过程比以往更有见识。

有用的链接 (Useful links)

  • Jupyter Notebook dashboard sample

    Jupyter Notebook仪表板示例

  • Web pivot table live demo

    Web数据透视表实时演示

  • Pythonic Data Cleaning With Pandas and NumPy

    使用Pandas和NumPy进行Pythonic数据清理

  • Exploratory Data Analysis With Python and Pandas on Coursera

    在Coursera上使用Python和Pandas进行探索性数据分析

翻译自: https://medium.com/python-in-plain-english/data-visualization-with-python-and-javascript-c1c28a7212b2

http://www.taodudu.cc/news/show-995263.html

相关文章:

  • github gists 101使代码共享漂亮
  • 大熊猫卸妆后_您不应错过的6大熊猫行动
  • jdk重启后步行_向后介绍步行以一种新颖的方式来预测未来
  • scrapy模拟模拟点击_模拟大流行
  • plsql中导入csvs_在命令行中使用sql分析csvs
  • 交替最小二乘矩阵分解_使用交替最小二乘矩阵分解与pyspark建立推荐系统
  • 火种 ctf_分析我的火种数据
  • 分析citibike数据eda
  • 带有postgres和jupyter笔记本的Titanic数据集
  • 机器学习模型 非线性模型_机器学习模型说明
  • 算命数据_未来的数据科学家或算命精神向导
  • 熊猫数据集_熊猫迈向数据科学的第三部分
  • 充分利用UC berkeleys数据科学专业
  • 铁拳nat映射_铁拳如何重塑我的数据可视化设计流程
  • 有效沟通的技能有哪些_如何有效地展示您的数据科学或软件工程技能
  • vue取数据第一个数据_我作为数据科学家的第一个月
  • rcp rapido_为什么气流非常适合Rapido
  • 算法组合 优化算法_算法交易简化了风险价值和投资组合优化
  • covid 19如何重塑美国科技公司的工作文化
  • 蒙特卡洛模拟预测股票_使用蒙特卡洛模拟来预测极端天气事件
  • 微生物 研究_微生物监测如何工作,为何如此重要
  • web数据交互_通过体育运动使用定制的交互式Web应用程序数据科学探索任何数据...
  • 熊猫数据集_用熊猫掌握数据聚合
  • 数据创造价值_展示数据并创造价值
  • 北方工业大学gpa计算_北方大学联盟仓库的探索性分析
  • missforest_missforest最佳丢失数据插补算法
  • 数据可视化工具_数据可视化
  • 使用python和pandas进行同类群组分析
  • 敏捷数据科学pdf_敏捷数据科学数据科学可以并且应该是敏捷的
  • api地理编码_通过地理编码API使您的数据更有意义

使用python和javascript进行数据可视化相关推荐

  1. python与excel做数据可视化-python做可视化数据分析,究竟怎么样?

    Python做可视化数据分析也是可以的,只是对比起来专业的可视化工具有些得不应手,做出来的图可能不太美观.Python用来处理数据,用来分析绝对可以.我觉得想要可视化可以使用专门的可视化工具. 不过, ...

  2. 推荐14款基于javascript的数据可视化工具

    2019独角兽企业重金招聘Python工程师标准>>> 随着数据可视化概念逐年火热,有较多优秀的图表开源库和制作工具脱颖而出,下面,我们就拿其中比较有名的 14个产品进行简要介绍. ...

  3. python与excel做数据可视化-我在工作中是怎么玩数据的—数据可视化系列教程—Python篇...

    一. 为什么是Python? Python现在已经成为数据科学的语言!基于 Python 代码实现批量化,流程化的数据探索与汇报!按照地产大佬***的话讲--就是重复性的工作直接用Python搞定就可 ...

  4. 毕业设计-基于Python爬虫的疫情数据可视化系统

    基于Python爬虫的疫情数据可视化系统 采用ECharts+Flask+Requests架构: 源码加3105088663

  5. 30行python代码设计_30行Python代码实现3D数据可视化

    原标题:30行Python代码实现3D数据可视化 作者:潮汐 来源:Python技术 欢迎来到 编程教室~ 我们之前的文章中有讲解过不少 Matplotlib 的用法,比如: 之前我们基本都是用它来绘 ...

  6. Python项目实战:数据可视化与股票数据分析-关东升-专题视频课程

    Python项目实战:数据可视化与股票数据分析-333人已学习 课程介绍         本视频内容包括使用Matplotlib绘制图表.MySQL数据库.Python访问数据库和Lambda表达式. ...

  7. Python爬虫实战,pyecharts模块,Python实现中国地铁数据可视化

    前言 利用Python实现中国地铁数据可视化.废话不多说. 让我们愉快地开始吧~ 开发工具 Python 版本:3.6.4 相关模块: requests模块; wordcloud模块; 熊猫模块; n ...

  8. 新书《Python Qt GUI与数据可视化编程》

    经过一年多写作和出版社的编辑加工,我的第二本书<Python Qt GUI与数据可视化编程>马上就正式上架了,敬请关注. 本书介绍在Python中使用PyQt5和其他模块进行GUI和数据可 ...

  9. Python爬取豆瓣+数据可视化

    博客原文和源码下载:Python爬取豆瓣+数据可视化 前言 前段时间应我姐邀请,看了一下Python爬虫.不得不说Python的语法确实简洁优美,可读性强,比较接近自然语言,非常适合编程的初学者上手. ...

最新文章

  1. 20175320 2018-2019-2 《Java程序设计》第2周学习总结
  2. 利用动态加载模板,配合ajax实现无刷新操作
  3. Sharding-JDBC(二)2.0.3版本实践
  4. 音视频技术开发周刊 | 184
  5. 简单实现vue验证码60秒倒计时功能
  6. 简自动类型提升,精度损失类型强制转换,常用转义字符,简单帮你回顾Java基本数据类型整形浮点型字符型布尔型Boolean及其运算规则
  7. 了解git的命令行使用
  8. CentOS 6.6 搭建Zabbix 3.0.3 过程
  9. absolute如果找不到定位父元素那么会相对于谁进行定位_selenium+python面试题目总结,完整度80%,看看你会多少?...
  10. curl: (52) Empty reply from server
  11. Android:获取存储卡路径的方式
  12. 【数字信号处理】基于matlab数字信号同步压缩变换【含Matlab源码 1534期】
  13. HTML URL 编码参考手册:ASCII 编码参考手册
  14. zblog插件全自动采集伪原创发布插件免费
  15. 超越postman,国产接口联调工具新选择-ApiPost
  16. 用python完成最基础ems项目
  17. 个人所得税计算java版
  18. 煮一壶清茶,悟一种人生
  19. 记一次生产数据库事故
  20. docker搭建 JRebel 验证服务器 和 IDEA 验证服务器

热门文章

  1. linux 下source命令
  2. CodeForces - 1152B二进制+思维
  3. java特性多态,90%的人看完都说好
  4. 浅析STM32之usbh_def.H
  5. TCP/IP WebSocket MQTT
  6. 通用的权限管理系统发布
  7. SpringCloud与Seata分布式事务初体验
  8. openstack服务编排
  9. 用过C#的朋友可能认为它是一种十分安全的语言,其实C#也可以做到经典的缓冲区溢出。 本文章将用一个实例来描述C#究竟是如何发生缓冲区溢出的! 首先建立一个C# Console工程,并开启工程的“允许
  10. Xcode中捕获iphone/ipad/ipod手机摄像头的实时视频数据