df.sum(axis='columns')
df['Total'] = df.sum(axis='columns')
df
df.plot(y='Total')
df['Group1'] = df.loc[:, 'KBS':'SBS'].sum(axis='columns')
df['Group2'] = df.loc[:, 'TV CHOSUN':'MBN'].sum(axis='columns')
df
df.plot(y=['Group1', 'Group2'])
df['Genre'].unique()
[df['Genre']=='Blues']
df[df['Genre']=='Blues'] # Boolean_Series >> df
.str.contains('Blues')
.str.startswith('Blues')
df[df['Genre'].str.contains('Blues')]
df[df['Genre'].str.startswith('Blues')]
df['Contains Blues'] = df['Genre'].str.contains('Blues')
df
str.split
df['소재지도로명주소'].str.split()
# 첫번째 공백만 분리
df['소재지도로명주소'].str.split(n=1)
# DataFrame 생성
df['소재지도로명주소'].str.split(n=1, expand=True)
adress = df['소재지도로명주소'].str.split(n=1, expand=True)
# adress의 0번 인덱스 값을 관할구역 column의 값으로 지정
df['관할구역'] = adress[0]
df
# 사전형을 통해 df의 값에 대응하는 새로운 값 지정
brand_nation = {
'Dell': 'U.S.',
'Apple': 'U.S.',
'Acer': 'Taiwan',
'HP': 'U.S.',
'Lenovo': 'China',
'Alienware': 'U.S.',
'Microsoft': 'U.S.',
'Asus': 'Taiwan'
}
df['brand'].map(brand_nation)
df['brand_nation'] = df['brand'].map(brand_nation)
df
groupby
메소드nation_groups = df.groupby('brand_nation')
type(nation_groups)
pandas.core.groupby.generic.DataFrameGroupBy
nation_groups.count()
nation_groups.max()
nation_groups.mean()
nation_groups.first()
nation_groups.last()
nation_groups.plot(kind='box', y='price')
nation_groups.plot(kind='hist', y='price')
merge
메소드Product
pd.merge(price_df, quantity_df, on='Product')
pd.merge(price_df, quantity_df, on='Product', how='left')
pd.merge(price_df, quantity_df, on='Product', how='right')
pd.merge(price_df, quantity_df, on='Product', how='outer')
* 출처: 코드잇 - 데이터 사이언스 입문