Table of Contents
1. Wget
2. Pendulum
3. imbalanced-learn
4. FlashText
5. fuzzywuzzy
6. PyFlux
7. Ipyvolume
8. Dash
九、Gym
总结
Home Backend Development Python Tutorial Nine super useful Python libraries for data science

Nine super useful Python libraries for data science

Apr 17, 2023 am 09:25 AM
python programming language develop

In this article, we will look at some Python libraries for data science tasks, instead of the more common libraries such as panda, scikit-learn, and matplotlib. Although libraries like panda and scikit-learn are commonly used in machine learning tasks, it is always beneficial to understand other Python products in this field.

1. Wget

Extracting data from the Internet is one of the important tasks of a data scientist. Wget is a free utility that can be used to download non-interactive files from the Internet. It supports HTTP, HTTPS, and FTP protocols, as well as file retrieval through HTTP's proxy. Since it is non-interactive, it can work in the background even if the user is not logged in. So next time you want to download all the images on a website or a page, wget can help you.

Installation:

$ pip install wget
Copy after login

Example:

import wget
url = 'http://www.futurecrew.com/skaven/song_files/mp3/razorback.mp3'

filename = wget.download(url)
100% [................................................] 3841532 / 3841532

filename
'razorback.mp3'
Copy after login

2. Pendulum

For those who get frustrated when dealing with date and time in python, Pendulum is for you. It is a Python package that simplifies datetime operations. It is a simple replacement for Python's native classes. See the documentation for deeper learning.

Installation:

$ pip install pendulum
Copy after login

Example:

import pendulum

dt_toronto = pendulum.datetime(2012, 1, 1, tz='America/Toronto')
dt_vancouver = pendulum.datetime(2012, 1, 1, tz='America/Vancouver')

print(dt_vancouver.diff(dt_toronto).in_hours())

3
Copy after login

3. imbalanced-learn

It can be seen that when the number of samples in each class is basically the same, Most classification algorithms work best when the data needs to be balanced. However, most of the real-life cases are imbalanced data sets, which have a great impact on the learning phase and subsequent predictions of the machine learning algorithm. Fortunately, this library is designed to solve this problem. It is compatible with scikit-learn and is part of the scikit-lear-contrib project. Try using this the next time you encounter an unbalanced data set.

Installation:

$ pip install -U imbalanced-learn

# 或者

$ conda install -c conda-forge imbalanced-learn
Copy after login

Example:

Please refer to the document for usage methods and examples.

4. FlashText

In NLP tasks, cleaning text data often requires replacing keywords in sentences or extracting keywords from sentences. Typically this can be done using regular expressions, but this can become cumbersome if the number of terms being searched runs into the thousands. Python's FlashText module is based on the FlashText algorithm and provides a suitable alternative for this situation. The great thing about FlashText is that the run time is the same regardless of the number of search terms. You can learn more here.

Installation:

$ pip install flashtext
Copy after login

Example:

Extract keywords

from flashtext import KeywordProcessor
keyword_processor = KeywordProcessor()

# keyword_processor.add_keyword(<unclean name>, <standardised name>)

keyword_processor.add_keyword('Big Apple', 'New York')
keyword_processor.add_keyword('Bay Area')
keywords_found = keyword_processor.extract_keywords('I love Big Apple and Bay Area.')

keywords_found
['New York', 'Bay Area']
Copy after login

Replace keywords

keyword_processor.add_keyword('New Delhi', 'NCR region')

new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.')

new_sentence
'I love New York and NCR region.'
Fuzzywuzzy
Copy after login

5. fuzzywuzzy

The name of this library sounds strange, but fuzzywuzzy is a very useful library when it comes to string matching. Operations such as calculating string matching degree and token matching degree can be easily implemented, and records stored in different databases can also be matched easily.

Installation:

$ pip install fuzzywuzzy
Copy after login

Examples:

from fuzzywuzzy import fuzz
from fuzzywuzzy import process

# 简单匹配度

fuzz.ratio("this is a test", "this is a test!")
97

# 模糊匹配度
fuzz.partial_ratio("this is a test", "this is a test!")
 100
Copy after login

More interesting examples can be found in the GitHub repository.

6. PyFlux

Time series analysis is one of the most common problems in the field of machine learning. PyFlux is an open source library in Python built for working with time series problems. The library has an excellent collection of modern time series models, including but not limited to ARIMA, GARCH, and VAR models. In short, PyFlux provides a probabilistic approach to time series modeling. Worth trying.

Installation

pip install pyflux
Copy after login

Example

Please refer to the official documentation for detailed usage and examples.

7. Ipyvolume

Result display is also an important aspect in data science. Being able to visualize the results will be a great advantage. IPyvolume is a Python library that can visualize 3D volumes and graphics (such as 3D scatter plots, etc.) in Jupyter notebooks and requires only a small amount of configuration. But it is still in the pre-1.0 version stage. A more appropriate metaphor to explain is: IPyvolume's volshow is as useful for three-dimensional arrays as matplotlib's imshow is for two-dimensional arrays. More available here.

Using pip

$ pip install ipyvolume
Copy after login

Using Conda/Anaconda

$ conda install -c conda-forge ipyvolume
Copy after login

Example

Animation

Nine super useful Python libraries for data science

body Draw

Nine super useful Python libraries for data science

8. Dash

Dash is an efficient Python framework for building web applications. It is designed based on Flask, Plotly.js and React.js, and is bound to many modern UI elements such as drop-down boxes, sliders and charts. You can directly use Python code to write relevant analysis without having to Use javascript. Dash is great for building data visualization applications. These applications can then be rendered in a web browser. The user guide is available here.

Installation

pip install dash==0.29.0# 核心 dash 后端
pip install dash-html-components==0.13.2# HTML 组件
pip install dash-core-components==0.36.0# 增强组件
pip install dash-table==3.1.3# 交互式 DataTable 组件(最新!)
Copy after login

Example The following example shows a highly interactive chart with drop-down functionality. When the user selects a value in the dropdown menu, the application code dynamically exports data from Google Finance to a panda DataFrame.

Nine super useful Python libraries for data science

九、Gym

OpenAI 的 Gym 是一款用于增强学习算法的开发和比较工具包。它兼容任何数值计算库,如 TensorFlow 或 Theano。Gym 库是测试问题集合的必备工具,这个集合也称为环境 —— 你可以用它来开发你的强化学习算法。这些环境有一个共享接口,允许你进行通用算法的编写。

安装

pip install gym
Copy after login

例子这个例子会运行CartPole-v0环境中的一个实例,它的时间步数为 1000,每一步都会渲染整个场景。

总结

以上这些有用的数据科学 Python 库都是我精心挑选出来的,不是常见的如 numpy 和 pandas 等库。如果你知道其它库,可以添加到列表中来,请在下面的评论中提一下。另外别忘了先尝试运行一下它们。

The above is the detailed content of Nine super useful Python libraries for data science. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

How to run sublime code python How to run sublime code python Apr 16, 2025 am 08:48 AM

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

See all articles