In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use Sample in pandas. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Sample
Sample is used to randomly select several rows or columns from the DataFrame.
Usage:
DataFrame.sample (n=None, frac=None, replace=False, weights=None, random_state=None, axis=None)
Parameter function:
(1) n: the number of rows to be extracted
(2) frac: the proportion of rows extracted
Frac=0.8, for example, extracts 80% of them.
(3) replace: whether it is sampled back.
True: there is a return sampling
False: unreturned sampling
(4) weights: character index or probability array
(5) random_state: random number generator seed
(6) axis: select the row or column from which to extract data
Axis=0: extract rows
Axis=1: extract column
For example, five rows are randomly selected from the df:
Sample1 = df.sample (nasty 5) sample1
Take 60% of the rows randomly from df, and set random number seeds to get the same sample each time:
Sample2 = df.sample (frac=0.6,random_state=2) sample2
This is the end of the article on "how to use Sample in pandas". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.