当前位置:网站首页>Introduction to classification data cotegory and properties and methods of common APIs
Introduction to classification data cotegory and properties and methods of common APIs
2022-06-26 04:50:00 【I am a little monster】
pandas There is a classification data type in category, Categorical data types have the following advantages :
(1) Storing data in this way saves more memory , Increase speed , Especially when the data set contains a lot of duplicate strings
(2) When a bad quality exists in a certain order ( Like the Likert scale ) when , It should be converted into classified data
(3) There are some python The library can handle classified data ( For example, fitting statistical models )
Use astype Convert data to catecory For data types, refer to astype Convert data type _ I am a little monster blog -CSDN Blog
The reference tables given below give the possible reclassifications series Actions performed on , Below the table are examples of attribute methods in the table
| Properties or methods | explain |
| Series.cat.categories | Category |
| Series.cat.ordered | Whether the categories are in order |
| Series.cat.codes | Return the certificate code of the category |
| Series.cat.rename_categories() | Rename category |
| Series.cat.reorder_categories() | Reorder categories |
| Series.cat.add_categories() | Add a new category |
| Series.cat.remove_categories() | Delete category |
| Series.cat.remove_unused_categories() | Delete unused categories |
| Series.cat.set_categories() | Set new category |
| Series.cat.as_order() | Sort categories |
| Series.cat.as_unordered() | Is the category out of order |
import pandas as pd
import seaborn as sns
tips=sns.load_dataset('tips')
t=tips.head(10)
t.loc[[1,4,7],'total_bill']='missing'
print(t.dtypes)
print(t['sex'].cat.categories)
The output is as follows :
total_bill object
tip float64
sex category
smoker category
day category
time category
size int64
dtype: object
------------------------------------------------
Index(['Male', 'Female'], dtype='object')
[Finished in 1.7s]
边栏推荐
- 2022.2.10
- 2022.2.15
- PHP small factory moves bricks for three years - interview series - my programming life
- An unexpected attempt (Imperial CMS list template filters spaces and newlines in smalltext introduction)
- Multipass中文文档-设置驱动
- YOLOV5训练结果的解释
- "Eight hundred"
- Numpy data input / output
- Nightmare
- 2.8 learning summary
猜你喜欢

企业的产品服务怎么进行口碑营销?口碑营销可以找人代做吗?

1.20 learning summary

Thinkphp6 implements a simple lottery system

0622 horse palm fell 9%

天才制造者:独行侠、科技巨头和AI|深度学习崛起十年

A new paradigm for large model application: unified feature representation optimization (UFO)

1.18 learning summary

Multipass Chinese document - setup driver

PowerShell runtime system IO exceptions

Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
随机推荐
The select option in laravel admin contains a large amount of data
Database design (3): database maintenance and optimization
Datetime data type ---now() gets the current time, datetime() creation date, performs mathematical operations, and to_ Datetime() converts to date type and extracts various parts of date
PowerShell runtime system IO exceptions
PHP syntax summary
Some parameter settings and feature graph visualization of yolov5-6.0
Dameng database backup and restore
A new paradigm for large model application: unified feature representation optimization (UFO)
Illustration of ONEFLOW's learning rate adjustment strategy
Tips for using idea
2022.2.17
YOLOv5-6.0的一些参数设置和特征图可视化
图像翻译/GAN:Unsupervised Image-to-Image Translation with Self-Attention Networks基于自我注意网络的无监督图像到图像的翻译
2022.2.11
numpy 通用函数
Physical design of database design (2)
Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
Rsync common error messages (common errors on the window)
Compiling and installing phpredis extension on MAC
问题随记 —— pip 换源