在Pandas的MultiIndex DataFrame中删除重复项 [英] Drop duplicate in multiindex dataframe in pandas

查看:234
本文介绍了在Pandas的MultiIndex DataFrame中删除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种有效的方法来使用Pandas在多索引数据框中删除重复的列.

I am looking to an efficient method to drop duplicate columns in a multiindex dataframe with Pandas.

我的数据:

TypePoint      TIME     Test   ...         T1      T1
-                 S    Unit1   ...       unit    unit
(POINT, -)                     ...                   
24001         90.00  100.000   ...     303.15  303.15
24002        390.00  101.000   ...     303.15  303.15
            ...      ...   ...        ...     ...
24801         10000  102.000   ...     303.15  303.15
24802         10500  103.000   ...     303.15  303.15

头包含两个信息.变量的名称及其单位. 我想删除变量"T1"(重复的变量).

The header contain two information. The variable's name and its unit. I would like to drop the variable "T1" (duplicate variable).

  • .drop_duplicates()不起作用.我收到缓冲区的维数错误(预期为1,为2)"错误.

  • .drop_duplicates() don't work. I get "Buffer has wrong number of dimensions (expected 1, got 2)" error.

.drop(Data('T1','unit'),axis = 1)也不起作用.这样就放下了两列,而不仅仅是其中的一列.

.drop(Data('T1','unit'),axis=1) don't work either. That drop the two column and not just only one of them.

感谢您的帮助

推荐答案

我认为您可以使用双

I think you can use double T:

print df
  TypePoint   TIME  Test      T1        
          -      S Unit1    unit    unit
0     24001     90   100  303.15  303.15
1     24002    390   101  303.15  303.15
2     24801  10000   102  303.15  303.15
3     24802  10500   103  303.15  303.15

print df.T.drop_duplicates().T
  TypePoint   TIME  Test      T1
          -      S Unit1    unit
0     24001     90   100  303.15
1     24002    390   101  303.15
2     24801  10000   102  303.15
3     24802  10500   103  303.15

这篇关于在Pandas的MultiIndex DataFrame中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆