Get the App
SLTechnology News&Howtos  ›  Development  › 

How to select rows in Pandas data box in Python

Shulou Source: shulou.com Published: 2022-06-03 17:38:21 11月13日 Update

This article mainly introduces the Python Pandas data box how to select rows, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Description

1. Boolean index (df [df ['col'] = = value])

2. Location index (df.iloc [...])

3. Tag index (df.xs (...))

4. Df.query (...) Application program interface

Each example and suggestions for when to use certain technologies are shown below. Let's assume that our standard is column 'Awareness Foo'.

(note about performance: for each basic type, we can keep it simple by using Pandas API, or we can take risks outside of API, usually into NumPy, and speed up. )

Set up

The first thing we need to do is to determine a condition that will be used as our criteria for selecting rows. We will start with the case of OP column_name = = some_value and include some other common use cases.

Borrow @ unutbu:

Import pandas as pd, numpy as npdf = pd.DataFrame ({'Aging:' foo bar foo bar foo bar foo foo'.split (), 'dating:' one one two three two two one three'.split (), 'dating: np.arange (8),' dating: np.arange (8) * 2}) Thank you for reading this article carefully I hope the article "how to choose rows in Pandas data boxes in Python" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles selections indexes data conditions standards items values locations interests can be passed at the same time Boolean common applications suggestions performance technology interfaces more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Xiaomi Redmi Docker OPPO Reno