Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pd.cut in pandas

>>> pd.qcut(range(5), 4, labels=False)
array([0, 0, 1, 2, 3])
Comment

pd.cut in pandas

>>> pd.qcut(range(5), 3, labels=["good", "medium", "bad"])
... 
[good, good, medium, bad, bad]
Categories (3, object): [good < medium < bad]
Comment

Dataframe cut

import pandas as pd

#设置切分区域
listBins = [0, 10, 20, 30, 40, 50, 60, 1000000]

#设置切分后对应标签
listLabels = ['0_10','11_20','21_30','31_40','41_50','51_60','61及以上']

#利用pd.cut进行数据离散化切分
"""
pandas.cut(x,bins,right=True,labels=None,retbins=False,precision=3,include_lowest=False)
x:需要切分的数据
bins:切分区域
right : 是否包含右端点默认True,包含
labels:对应标签,用标记来代替返回的bins,若不在该序列中,则返回NaN
retbins:是否返回间距bins
precision:精度
include_lowest:是否包含左端点,默认False,不包含
"""
df['fenzu'] = pd.cut(df['data'], bins=listBins, labels=listLabels, include_lowest=True)
Comment

PREVIOUS NEXT
Code Example
Python :: Python match.re and match.string 
Python :: selenium python get image from url 
Python :: How to get the Tkinter Label text 
Python :: email validation using django 
Python :: dataframe coulmn to list 
Python :: Odd number without loop in python 
Python :: run flask in background 
Python :: use chrome console in selenium 
Python :: python loop over list 
Python :: python frozenset 
Python :: install multiple versions of python 
Python :: pyhton mcq 
Python :: python http post file 
Python :: get pattern from string python 
Python :: python dataframe limit rows 
Python :: comparing values in python 
Python :: get status code python 
Python :: pandas mask multiple condition 
Python :: prime numbers 1 to input 
Python :: simple click counter in python 
Python :: how to kill python process started by excel 
Python :: john cabot 
Python :: tranking de perosnas python 
Python :: python openstreetmap multiple latitude 
Python :: pandas replace inf with 0 
Shell :: restart apache ubuntu 
Shell :: ubuntu uninstall redis 
Shell :: remove identifier files wsl2 
Shell :: notepad++ ubuntu 
Shell :: install metasploitable on ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =