[python] Pandas 데이터 프레임에 행 삽입 - 리뷰나라
데이터 프레임이 있습니다. s1 = pd.Series([5, 6, 7]) s2 = pd.Series([7, 8, 9]) df = pd.DataFrame([list(s1), list(s2)], columns = ["A", "B", "C"]) A B C 0 5 6 7 1 7 8 9 [2 rows x 3 columns] 다음을 얻으려면 첫 번째 행 [2, 3, 4]을 추가
daplus.net
번역체지만 중간 or 맨위에 행을 삽입하는 수많은 방법들이 있다.
https://zephyrus1111.tistory.com/64
[Pandas] 12. 행 추가/삭제하기
안녕하세요~ 꽁냥이에요. 이번 포스팅은 Pandas에서 새로운 행 데이터를 데이터프레임에 추가, 삭제하는 방법에 대해서 알아보려고 합니다. 1. Pandas 행 추가하기 2. Pandas 행 삭제하기 1. Pandas 행
zephyrus1111.tistory.com
중간에 삽입하는 코드도 만들어줬다. 장사 잘되는 블로그는 이유가 있다.
## 원하는 위치에 넣기
new_data = {
'이름' : '아이린',
'나이' : 26,
'키' : 160
}
idx = 1 ## 원하는 인덱스
temp1 = df[df.index < idx]
temp2 = df[df.index >= idx]
df = temp1.append(new_data,ignore_index=True).append(temp2, ignore_index=True)
'파이썬. 데이터분석 > Pandas' 카테고리의 다른 글
| Pandas DataFrame : 데이터 행,열 바꾸는 방법들 (0) | 2022.07.02 |
|---|---|
| Pandas DataFrame : 특정 행 index만 바꾸기. (0) | 2022.06.25 |
| Pandas DataFrame : insert 열삽입 (0) | 2022.06.24 |
| Pandas DataFrame : del / drop 행, 열 삭제, 특정행 삭제 (0) | 2022.06.24 |
| Pandas DataFrame : apply, lambda (0) | 2022.06.22 |