본문 바로가기

컴퓨팅

Pandas_DataFrame _processing_Tech

1. df[조건형] -> 특정 칼럼 조건에 맞는 행으로 모든 칼럼 출력

individual_features_df = []
for i in range(0, len(df_num.columns) - 1): # -1 because the last column is SalePrice
    tmpDf = df_num[[df_num.columns[i], 'SalePrice']]
    tmpDf = tmpDf[tmpDf[df_num.columns[i]] != 0]
    individual_features_df.append(tmpDf)

 

2.  특정 데이터타입의 칼럼만 알고싶을 때

#1
s = (df.dtypes == 'object')
object_cols = list(s[s].index)
print("Categorical variables:")
print(object_cols)

#2
numeric_feats=all_data.dtypes[all_data.dtypes != 'object'].index

 

3. 개체 조건에 따른 데이터를 새로운 컬럼에 넣기 or 연속형 데이터를 범주형으로 변환

df['SalePrice_band']=0
df.loc[df['SalePrice']<50000 , 'SalesPrice_band']=1
df.loc[(df['SalePrice']>=50000) & (df['SalePrice']<100000) , 'SalesPrice_band'] = 2
df.loc[(df['SalePrice']>=100000) & (df['SalePrice']<125000) , 'SalesPrice_band'] = 3

 

4. loc를 통한 칼럼 인덱싱 + concat으로 합치기

all_data=pd.concat([train.loc[:,'MSSubClass':'SaleCondition'], test.loc[:,'MSSubClass':'SaleCondition']])

 

5. 특정칼럼을 제외하고 데이터프레임 출력하기

all_data[all_data.columns.difference(['SalePrice'])]

'컴퓨팅' 카테고리의 다른 글

Python_generator  (0) 2021.02.16
관계형 데이터 모델링_모든 내용  (0) 2021.01.31
카디널리티란  (0) 2021.01.16
Anaconda_prompt  (0) 2021.01.16
python_English to Korean  (0) 2021.01.15