divide 함수 축 질문
60
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.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
구글 그래피티 마켓 오류...?!
0
8
2
디스코드 소통창구는 없어졌나요 ??
0
7
1
FOREIGN KEY 정리하기, 영상대로 SQL코드 복붙해도 안되요.
0
5
1
모델 서빙과 관련된 강좌 출시 예정된 바가 있으신지 여쭤봅니다!
0
7
1
모델 서빙과 관련된 강좌가 출시되는지 질문드립니다.
0
6
1
20번강좌에 대한 질문입니다.
0
6
1
6-6
0
18
1
작업형 1 유형 부분
0
19
2
수강평 이벤트
0
23
2
작업형 1 (삭제예정, 구 버전)
0
34
2
강의노트는 어디있나요?
0
21
1
노션 학습 자료 권한 요청
0
17
1
수강기간 연장 문의드립니다.
0
26
1
2유형 레이블 인코딩 VS 원핫 인코딩
0
26
3
part2강의 문의사항입니다.
0
23
2
수강기간 연장 문의드립니다.
0
28
1
인덱스 슬라이싱
0
28
2
코드를 첨부해야하는 이유가 있나요?
0
22
2
파이썬 연습문제 6번 관련 문의
0
58
1
쥬피터노트북이 안깔려요
0
451
1
pandas 연습문제 4번 관련
0
354
1
Pandas 연습문제 4. apply 활용 질문
0
560
1
마크다운 blank line
0
813
1
내국인 생활인구.csv 다운위치
0
599
1

