[英]Pandas: Selecting rows in a table
I am trying to select these rows (where T-stage = 3 AND N-stage = 0 AND Radiation = 1) from three columns (T-stage, N-stage, and Radiation) with Python from the Table below.我正在尝试使用下表中的 Python 从三列(T-stage、N-stage 和 Radiation)中 select 这些行(其中 T-stage = 3 AND N-stage = 0 AND Radiation = 1)。 I used the following but the results is not what was expected:我使用了以下内容,但结果不是预期的:
df=pd.read_csv('Mydata.csv') // Loading my data df=pd.read_csv('Mydata.csv') // 加载我的数据
#I tried the two approaches below, but the results were not what I expected. #我尝试了以下两种方法,但结果不是我预期的。
A = ((df['T-stage'] == 3) | (df['N-stage'] == 0 | (df['Radiation'] == 1))) A = ((df['T-stage'] == 3) | (df['N-stage'] == 0 | (df['Radiation'] == 1)))
or或者
B = ((df['T-stage'] == 3) & (df['N-stage'] == 0 & (df['Radiation'] == 1))) B = ((df['T-stage'] == 3) & (df['N-stage'] == 0 & (df['Radiation'] == 1)))
Seems some ()
mismatch, for each condition use one ()
:似乎有些()
不匹配,对于每个条件使用一个()
:
B = df[(df['T-stage'] == 3) & (df['N-stage'] == 0) & (df['Radiation'] == 1)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.