import pandas as pd 

df = pd.read_csv('./data2/population.csv', encoding='CP949') 
 
# 컬럼을 공백을 기준으로 분할
df[['code','name']] = df.type.str.split(" ",expand=True) 

df['code_len'] = df['code'].apply(len)

# 컬럼 조회
print(df.columns.values)

# 컬럼 순서 조정
df = df[['code', 'code_len', 'name', 'Y2015', 'Y2016', 'Y2017', 'Y2018']]

# code_len값이 2인것만 추출
df = df.loc[df.code_len == 2]

df 

 

import matplotlib.pyplot as plt

# filtering
df2 = df[df['code'].isin(['11'])]
df3 = df[df['code'].isin(['21'])]

# print(df2)

plt.plot(['2015', '2016', '2017', '2018'], [int(df2.iloc[0]['Y2015']),int(df2.iloc[0]['Y2016']),int(df2.iloc[0]['Y2017']),int(df2.iloc[0]['Y2018'])])
plt.plot(['2015', '2016', '2017', '2018'], [int(df3.iloc[0]['Y2015']),int(df3.iloc[0]['Y2016']),int(df3.iloc[0]['Y2017']),int(df3.iloc[0]['Y2018'])])


plt.show()

 

population.csv
0.01MB

 

 

+ Recent posts