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
- PyQt5
- swift
- pandas
- MySQL
- PyQt
- javascript
- ASP
- node.js
- flutter
- 맛집
- 라즈베리파이
- mssql
- MS-SQL
- sqlite
- Unity
- 다이어트
- GIT
- 함수
- tensorflow
- urllib
- Excel
- IOS
- python
- port
- 리눅스
- ubuntu
- Linux
- 날짜
- PER
- 유니티
Archives
아미(아름다운미소)
pandas dataframe 컬럼비교 본문
예제1
import pandas as pd
# 예시 DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9], 'D': [10, 11, 12], 'E': [13, 14, 15]})
# 확인할 컬럼명 리스트
my_columns1 = ['A', 'B', 'C', 'D']
my_columns2 = ['A', 'B', 'C']
# DataFrame의 컬럼명 리스트
df_cols = df.columns.tolist()
# if-elif 조건 사용
if all(col in df_cols for col in my_columns1):
print('OK1')
elif all(col in df_cols for col in my_columns2):
print('OK2')
else:
print('Not OK')
OK1
예제2
import pandas as pd
# 예시 DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9], 'E': [13, 14, 15]})
# 확인할 컬럼명 리스트
my_columns1 = ['A', 'B', 'C', 'D']
my_columns2 = ['A', 'B', 'C']
# DataFrame의 컬럼명 리스트
df_cols = df.columns.tolist()
# if-elif 조건 사용
if all(col in df_cols for col in my_columns1):
print('OK1')
elif all(col in df_cols for col in my_columns2):
print('OK2')
else:
print('Not OK')
OK2
예제3
import pandas as pd
# 예시 DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'E': [7, 8, 9], 'F': [13, 14, 15]})
# 확인할 컬럼명 리스트
my_columns1 = ['A', 'B', 'C', 'D']
my_columns2 = ['A', 'B', 'C']
my_columns3 = ['A', 'B']
# DataFrame의 컬럼명 리스트
df_cols = df.columns.tolist()
# if-elif 조건 사용
if all(col in df_cols for col in my_columns1):
print('OK1')
elif all(col in df_cols for col in my_columns2):
print('OK2')
elif all(col in df_cols for col in my_columns3):
print('OK3')
else:
print('Not OK')
OK3
'랭귀지 > pandas' 카테고리의 다른 글
pandas 컬럼값변경 (0) | 2024.07.20 |
---|---|
pandas 참조 df 특정 컬럼값으로 값채우기 (0) | 2024.07.19 |
pandas filter (0) | 2024.07.17 |
pandas 여러열적용 (0) | 2024.07.16 |
pandas 조건 (0) | 2024.07.16 |
Comments