简体   繁体   English

Pandas 数据框逐列删除

[英]Pandas dataframe drop by column

I want to filter a dataframe based on values in a column.我想根据列中的值过滤数据框。 Here is how the df looks:这是 df 的样子:

    lead_snp Set_1 Set_2 Set_3 Set_4 Set_5  ... Set_4995 Set_4996 Set_4997 Set_4998 Set_4999 Set_5000
0  1:2444414     8     7     1    10    17  ...       16        6       10       12        8       12
1  1:1865298     2     2    11    21     6  ...       16        3       13       17        8        3
2  1:1865298     2     2    11    21     6  ...       16        3       13       17        8        3
3  1:1865298     2     2    11    21     6  ...       16        3       13       17        8        3
4  1:1865298     2     2    11    21     6  ...       16        3       13       17        8        3

When I run (lead_chrom_only_df.groupby("lead_snp").nunique().drop("lead_snp", axis=1)) , I get the error below:当我运行(lead_chrom_only_df.groupby("lead_snp").nunique().drop("lead_snp", axis=1)) ,出现以下错误:

KeyError: "['lead_snp'] not found in axis"

Not sure if I'm missing something obvious, thanks in advance.不确定我是否遗漏了一些明显的东西,提前致谢。

尝试通过as_index = False

out =  lead_chrom_only_df.groupby("lead_snp",as_index = False).nunique().drop("lead_snp", axis=1)

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

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