2012-10-09 3 views
0

concat()에서 반환 한 DataFrame을 이전하는 방법은 무엇입니까?Pandas transpose concat()

df = DataFrame([ 
      dict(a=1, b=10, c=41), 
      dict(a=1, b=20, c=42), 
      ]) 

concat([df, df]).T 

내가 얻을 :

AttributeError: 'DataFrame' object has no attribute 'dtypes' ! 

내가하려고하면 :

concat([df, df]).T.to_dict() 

내가 얻을 :

RuntimeError: maximum recursion depth exceeded in cmp 

나는이는 CONCAT에 의해 도입 된 중복에 관한 생각 ()를 사용했지만 해결 방법을 찾지 못했습니다.

+0

당신이 달성하려고하는 것을 설명 할 수 있습니까? – root

+0

df.T.to_dict()로 DataFrame 값을 unittest하는 데 사용했습니다. values ​​() – PhE

+1

fyi 최신 팬더 릴리스가 인덱스 중복을 지원할 수 있다고 생각합니다. 0.8.0 전에는 그렇지 않습니다. –

답변

1

당신은 keys를 사용하여 계층 인덱스를 지정할 수 있습니다

In [288]: concatenated = concat([df,df], keys=['first', 'second']) 

In [289]: print concatenated.T 
    first  second  
     0 1  0 1 
a  1 1  1 1 
b  10 20  10 20 
c  41 42  41 42 

In [290]: print concatenated.T.to_dict().values() 
[{'a': 1, 'c': 41, 'b': 10}, {'a': 1, 'c': 41, 'b': 10}, {'a': 1, 'c': 42, 'b': 20}, {'a': 1, 'c': 42, 'b': 20}]