groupby
함수 응용 프로그램을 디버그하려고 할 때 더미 함수를 사용하여 각 그룹의 함수로 "전달되는 내용을 확인하십시오"라는 것을 someone suggested 디버깅하려고합니다. 그룹에서 변환 또는 적용하기 위해 전달되는 판다 데이터 형식
single column transform
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
single column (nested) transform
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
multiple column transform
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
single column apply
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
single column (nested) apply
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
multiple column apply
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
은 그래서 것 같다
:- 이
- 단일 열 변환
import numpy as np import pandas as pd np.random.seed(0) # so we can all play along at home categories = list('abc') categories = categories * 4 data_1 = np.random.randn(len(categories)) data_2 = np.random.randn(len(categories)) df = pd.DataFrame({'category': categories, 'data_1': data_1, 'data_2': data_2}) def f(x): print type(x) return x print 'single column transform' df.groupby(['category'])['data_1'].transform(f) print '\n' print 'single column (nested) transform' df.groupby(['category'])[['data_1']].transform(f) print '\n' print 'multiple column transform' df.groupby(['category'])[['data_1', 'data_2']].transform(f) print '\n' print '\n' print 'single column apply' df.groupby(['category'])['data_1'].apply(f) print '\n' print 'single column (nested) apply' df.groupby(['category'])[['data_1']].apply(f) print '\n' print 'multiple column apply' df.groupby(['category'])[['data_1', 'data_2']].apply(f)
이 내 표준 출력에 다음을 넣습니다 : 물론, 나는 게임을 해요 : 3
Series
- 단일 열 (중첩) : 2
Series
3DataFrame
- 여러 열 : 3
Series
3DataFrame
- 단일 열 변환
-
- 단일 열 적용 : (중첩) 3
Series
- 단일 열 : 4
DataFrame
- 복수 열 : 4
DataFrame
- 단일 열 적용 : (중첩) 3
여기 무슨 일 이니? 누구든지이 6 개의 호출이 각각 위에서 언급 한 일련의 객체가 지정된 함수로 전달되는 이유를 설명 할 수 있습니까?
2 질문을 확장하십시오 (완전히 대답 할 때 멋진 문서가 될 것입니다). groupy에 2 명의 그룹 작성자가있는 경우가 필요합니다 (입력 항목이 다르지만 그룹화 된 개체의 색인이 포함되어 있음) – Jeff
팬더를 배우려고 시도하면서이 유형의 질문이 많이있었습니다. 지난 한 달 동안. 이런 종류의 일에 좋은 자원이 있습니까? 나는. 하드 코어 소스 코드 다이빙/다시 쓰기와 달리 직관적 인 수준에서 팬더가 어떻게 작동하는지에 대한 일반적인 설명은 무엇입니까? 후드 아래의 – 8one6
은 일반적으로 코드를 작성하고 예제를 작성해야합니다. 일부는 간단하지만 groupby/indexing과 마찬가지로 많은 경우와 데이터 유형을 처리하므로 쉽지 않습니다. 자원은 워드 프로세서/요리 책, Wes의 책 및 SO 질문입니다. – Jeff