Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- 맛집
- 유니티
- tensorflow
- PER
- flutter
- Excel
- ubuntu
- Linux
- Unity
- port
- GIT
- ASP
- 리눅스
- urllib
- MS-SQL
- 다이어트
- pandas
- python
- PyQt
- mssql
- swift
- PyQt5
- 날짜
- sqlite
- MySQL
- 라즈베리파이
- node.js
- javascript
- IOS
- 함수
Archives
아미(아름다운미소)
pandas concat 본문
import pandas as pd
# 예시: 둘 다 빈 DataFrame이지만 컬럼이 다름
df1 = pd.DataFrame(columns=['a', 'b'])
df2 = pd.DataFrame(columns=['b', 'c'])
# 👉 모든 컬럼의 합집합 구하기
all_columns = sorted(set(df1.columns).union(set(df2.columns)))
# 👉 컬럼 맞춰주기 (reindex로 없으면 NaN 채움)
df1 = df1.reindex(columns=all_columns)
df2 = df2.reindex(columns=all_columns)
# 👉 concat
result = pd.concat([df1, df2], ignore_index=True)
print(result)
Comments