简体   繁体   English

使用 Pandas 在 where 条件下选择特定列

[英]Selecting specific columns in where condition using Pandas

I have a below Dataframe with 3 columns:我有一个下面有 3 列的数据框:

df = DataFrame(query, columns=["Processid", "Processdate", "ISofficial"])

In Below code, I get Processdate based on Processid==204 (without Column Names):在下面的代码中,我得到基于 Processid==204 的 Processdate(没有列名):

result = df[df.Processid == 204].Processdate.to_string(index=False)

But I wan the same result for Two columns at once without column names, Something like below code:但是我想在没有列名的情况下同时获得两列的相同结果,类似于下面的代码:

result = df[df.Processid == 204].df["Processdate","ISofficial"].to_string(index=False)

I know how to get above result but I dont want Column names, Index and data type.我知道如何获得上述结果,但我不想要列名、索引和数据类型。 Can someone help?有人可以帮忙吗?

I think you are looking for header argument in to_string parameters.我认为您正在to_string参数中寻找header参数。 Set it to False .将其设置为False

df[df.Processid==204][['Processdate', 'ISofficial']].to_string(index=False, header=False)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM