In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
The main content of this article is to explain "Python how to achieve data box technology", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Python how to achieve data box technology" bar!
1 data sub-box
The official definition of data box technology in Pandas: Bin values into discrete intervals, refers to the division of values into discrete intervals. For example, apples of different sizes are grouped into several pre-arranged boxes; people of different ages are divided into several age groups.
This technique can be very useful in data processing.
2 exampl
Let's look at the example first.
Import numpy as npimport pandas as pd
Ages = np.array ([5, 10, 36, 36, 12, 77, 89, 100, 30, 1) # Age data
The data are now divided into three sections and labeled as old, middle and young. Pandas provides an easy-to-use API that can be easily implemented.
Pd.cut (ages, 3, labels= ['green', 'middle', 'old'])
The result is as follows, and one line of code is implemented.
[green, medium, green, old, green, green]
During the operation of cut, the minimum and maximum values of the one-dimensional array are counted, and an interval length is obtained. Because three intervals need to be divided, three uniform intervals are obtained, as shown below.
Pd.cut (ages, 3) > interval is as follows: Categories (3, interval [float64]): [(0.901) 34.0] < (34.067.0) < (67.0100.0]]
The minimum value of the given data is 1, and the interval is left open and right closed by default, so in order to include 1, you need to extend the leftmost interval to the left by 0.1% (the total interval length). The default precision is 3 decimal places.
3 function prototype
After a preliminary understanding of cut through the above examples, it is easier to analyze the cut prototype.
The meaning of the parameter is as follows:
X: the class array data to be segmented. Note that it must be 1D.
Bins: simply understood as the sub-box rule, that is, the bucket. Support for int scalars and sequences
Right: indicates whether the right boundary of the interval is included. By default, it contains
Labels: tagged bins after segmentation
Retbins: indicates whether the split bins will be returned. It is not returned by default. If True, then:
Array ([0.901, 34. , 67. , 100. ]))
Include_lowest: whether the left side of the interval is open or closed. Default is on.
Duplicates: whether repeating intervals are allowed. Raise: not allowed, drop: allowed.
At this point, I believe you have a deeper understanding of "Python how to achieve data box technology", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.