Pandas 데이터프레임 컬럼명으로 컬럼 제거

1 개요[ | ]

Pandas 데이터프레임 컬럼명으로 컬럼 제거
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
df
df.drop(columns=['sepal_length','petal_length'])

2 방법 1: drop()[ | ]

inplace
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
df.drop(columns=['sepal_length','petal_length'], inplace=True)
df.head()
not-inplace
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
df2 = df.drop(columns=['sepal_length','petal_length'])
df2.head()

3 방법 2: del[ | ]

inplace
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
del df['sepal_length']
del df['petal_length']
df.head()
not-inplace
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
df2 = df.copy()
del df2['sepal_length']
del df2['petal_length']
(df.columns, df2.columns)

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}