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 | 31 |
Tags
- ASP
- node.js
- ubuntu
- IOS
- urllib
- PyQt5
- 날짜
- port
- pandas
- PER
- 리눅스
- Excel
- 라즈베리파이
- python
- MySQL
- javascript
- mssql
- sqlite
- tensorflow
- 유니티
- Unity
- Linux
- 함수
- 다이어트
- swift
- flutter
- GIT
- MS-SQL
- PyQt
- 맛집
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