아미(아름다운미소)

pandas 조건 본문

랭귀지/python

pandas 조건

유키공 2024. 6. 21. 08:20
import pandas as pd

# 샘플 데이터프레임 생성
df = pd.DataFrame({'A': [1, 2, 3, 4], 
                   'B': [10, 20, 30, 40],
                   'C': [100, 200, 300, 400]})

# A 컬럼이 2인 행의 B 컬럼 값을 변경
df.loc[df['A'] == 2, 'B'] = 99

print(df)
Comments