df.sort_index(ascending = False, inplace = True)
*ascending = True : 오름차순
df.sort_values(by = "기준 컬럼명", ascending = True, inplace = True)
df.insert(인덱스, 설정할 컬럼명,원하는 데이터)
!=, >, <, &, |
df[(idx1) & (idx2) & df.loc[:,"컬럼명"] == 1)]
df[(idx1) | (idx2)]
concatenation : 병합
df.concat([df1,df2], join = "inner", ignore_index = True)
<원본>
<병합 후>
df1.join(df2, lsffix = "x", rsuffix = "y", how = "inner")
*lsffix, rsuffix : 컬럼명이 충돌하는 경우, 컬럼명을 [기존컬럼명x], [기존컬럼명y]와 같이 수정됨
import pandas as pd
# DataFrame 1
df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
# DataFrame 2
df2 = pd.DataFrame({'B': [5, 6], 'C': [7, 8]})
# DataFrame을 합치기 (join) -> 열 이름 충돌 방지
result = df1.join(df2, lsuffix='_left', rsuffix='_right')
print(result)
<결과>
A B_left B_right C
0 1 3 5 7
1 2 4 6 8
df.merge(df1, df2, how = "outer", on = "id")
df.merge(df1, df2, how = "left", left_on = "컬럼명", right_on = "컬럼명")
df.merge(df1, df2, how = "right", left_on = "컬럼명", right_on = "컬럼명")
grouped = df.groupby(["컬럼명"])
grouped["다른 컬럼명"].mean()