divide 함수 축 질문
67
2 câu hỏi đã được viết
안녕하세요! pandas 연산기능 강의에서 이해가 가지 않는 부분이 있어 질문 드립니다.
df.divide(df.sum(axis=1), axis=0)
위 코드에서 열 축을 따라 왼쪽에서 오른쪽으로 나눗셈이 이루어지는데, 왜 axis=0 인가요? sum과 동일한 방향이면 똑같이 axis=1 이어야 할 것 같은데.. 헷갈립니다.
Câu trả lời 1
0
안녕하세요, 인프런 AI 인턴입니다. Questions about pandas operations are a common topic for those learning Python and pandas.
The divide function in pandas, when used as df.divide(df.sum(axis=1), axis=0), can indeed be a bit confusing at first glance. Here’s an explanation:
df.sum(axis=1): This operation calculates the sum of each row, returning a Series with the row sums. Theaxis=1parameter specifies that the operation is performed row-wise.df.divide(..., axis=0): Thedividefunction is used to perform element-wise division, and it divides each element of the DataFrame by the corresponding element in another DataFrame or Series. In this case, we divide each element in the original DataFrame by the corresponding row sum obtained in the previous step. Settingaxis=0means that we are aligning the Series with the rows of the DataFrame. Even though you’re dividing along rows, the alignment is happening row-wise, henceaxis=0.
The axis parameter in divide() refers to the alignment direction, rather than the direction of the operation itself. It helps to think of it as: “Using axis=0 aligns the operation along the rows rather than down the columns, which is why it’s set that way.”
For more insight, you can check out similar discussions in these posts:
Both links detail axes manipulations with pandas, specifically through examples with the apply function, which might be helpful to understand this concept.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
실습 2인데 커서아이디 같은거 다운로드 안내같은건 따로없나요??
0
3
1
5. 실습 (1) 개발 환경 준비와 프로젝트 구조 03:11
0
4
0
실행이 안 되는데요.
0
3
0
print 문법 실행 안 돼요.
0
3
1
작업형2 인코딩 질문
0
17
2
작업형 3 벼락치기 공부방법 질문
0
18
2
14강의 예시 데이터를 통한 답을 구하는 과정에서의 문의
0
7
1
영문 계정
0
8
1
기출 11회 작업형 2_전체 데이터 학습 여부
0
28
2
RateLimitError
0
14
2
예측값 결과 소수점 차이
0
24
2
여태까지 발견한 이슈들 공유드립니다.
1
27
1
기출 문제와 실전챌린지 연습문제 무엇부터 푸는게 나은가요?
0
27
1
전처리 train() test([ ])
0
19
2
작업형 1 배경지식 질문
0
25
2
옳게 풀은건지 질문드립니다!
0
16
1
roc_auc_score
0
29
2
재귀함수 연산법
0
15
2
파이썬 연습문제 6번 관련 문의
0
74
1
쥬피터노트북이 안깔려요
0
461
1
pandas 연습문제 4번 관련
0
357
1
Pandas 연습문제 4. apply 활용 질문
0
571
1
마크다운 blank line
0
821
1
내국인 생활인구.csv 다운위치
0
604
1

