2015-02-03 3 views
2

내가 Dataframe (아래)와 나는 아주 간단한 일을하고자하는 팬더를 방해하지 않고 :팬더 그룹화 개체 : 각 카테고리 내에서 정렬 값을 분류 순서

Climate_type Crop   
h. continental cabbage   200.148148 
       green_beans  226.925926 
       potato   316.981481 
       winter_wheat 292.333333 
subtropical  cabbage   519.925926 
       green_beans  338.833333 
       potato   365.740741 
       spring_wheat 278.388889 
temperate  cabbage   141.259259 
       green_beans  165.814815 
       potato   238.333333 
       winter_wheat 163.425926 
Name: Total_Irrigation_mm, dtype: float64 
: Climate_type의 순서를 방해하지 않고 각 Climate_type 내를

Climate_type Crop   
temperate  cabbage   141.259259 
       winter_wheat 163.425926 
       green_beans  165.814815 
h. continental cabbage   200.148148 
       green_beans  226.925926 
temperate  potato   238.333333 
subtropical  spring_wheat 278.388889 
h. continental winter_wheat 292.333333 
       potato   316.981481 
subtropical  green_beans  338.833333 
       potato   365.740741 
       cabbage   519.925926 
Name: Total_Irrigation_mm, dtype: float64 

당신은 Climate_type의 순서가 내가 원하는하지 않은 더 이상 유지되지 않는 것을 볼 : 내가 사용하는

정렬 나는 다음과 같은 얻을.

+0

'groupby'에'sort = False' 매개 변수를 전달하면 원하는 결과를 얻으실 수 있습니까? – EdChum

답변

0

당신은 일종의 각 그룹 내에서 다음 Climate_type에 그룹화하여이 작업을 수행 할 수 있습니다 :

In [54]: s.groupby(level=0, group_keys=False).apply(lambda x: x.order()) 

Out[54]: 
Climate_type Crop   
h.continental cabbage   200.148148 
       green_beans  226.925926 
       winter_wheat 292.333333 
       potato   316.981481 
subtropical spring_wheat 278.388889 
       green_beans  338.833333 
       potato   365.740741 
       cabbage   519.925926 
temperate  cabbage   141.259259 
       winter_wheat 163.425926 
       green_beans  165.814815 
       potato   238.333333 
dtype: float64 

참고하십시오 group_keys=False이 Climate_type이 결과에서 중복하지 필요합니다.

+0

감사합니다. – user2624750

관련 문제