[TIP / Pandas] Change Columns Order (열 순서 바꾸기)

2020. 10. 28. 23:21분석 Python/Pandas Tip

열 순서 바꾸기

def change_column_order(data , cols:list , positions:list) :   
    for position , col in zip(positions , cols) :
        pop_ = data.pop(col)
        data.insert(position, pop_.name, pop_.values)
    return data
data = change_column_order(data , cols =["key"], positions=[0])
728x90