简体   繁体   English

我如何只查看熊猫数据框中的某些行?

[英]How do I only look at certain rows in pandas dataframe?

I want to only look at the information of rows that correspond with 'U' and 'L' and 'R' under the category 'LU'. 我只想查看类别“ LU”下与“ U”,“ L”和“ R”相对应的行的信息。 What exactly do I have to write to grab that specific data? 我到底要写什么才能获取特定数据?

PTYPE   LU
1       E
2       U
3       R
4       L
5       R

test = data[data['LU'] == 'U' | 测试=数据[数据['LU'] =='U'| 'L' | 'L'| 'R' ] 'R']

I thought it might be the following statement above, but I got an error. 我以为可能是上面的以下陈述,但出现错误。 'U' 'L' and 'R' are also not integers. “ U”,“ L”和“ R”也不是整数。

method 1 方法1
query

data.query('LU in ("U", "L", "R")')

method 2 方法2
isin

data[data.LU.isin(list('ULR'))]

both result in 两者都导致

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据特定条件删除 Pandas DataFrame 的行? - How do I remove rows of a Pandas DataFrame based on a certain condition? 如何仅对数据帧中的某些行进行 KNN 测试? - How do I do KNN test only on certain rows in a dataframe? 如何仅根据熊猫中的标签选择某些行? - How do i select only certain rows based on label in pandas? 如何通过某些变量在 pandas dataframe 组中的行之间进行计算? - How do I do calculation between rows in pandas dataframe group by certain variable? 如何在 pandas DataFrame 中按索引仅保留一组特定行 - How to keep only a certain set of rows by index in a pandas DataFrame 如何使用规则在 pandas DataFrame 中按索引仅保留一组特定行 - How to keep only a certain set of rows by index in a pandas DataFrame with rule 如何使用 Pandas 仅遍历 DataFrame 中的某些行 - How to only iterate through certain rows in a DataFrame using Pandas 如何在Python Pandas数据帧列上执行数学运算,但仅限于满足某个条件? - How do I perform a math operation on a Python Pandas dataframe column, but only if a certain condition is met? 如何从使用熊猫上传的大型CSV文件中仅打印出某些行 - How do I print out only certain rows from a large CSV file uploaded using pandas 如何仅删除Pandas DataFrame中的特定行? - How do you delete only specific rows in a Pandas DataFrame?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM