<jupyter_start><jupyter_text>수정사항* 계산식을 코드로 바로 입력* Nan data table 수정* 추가데이터와 비교 (ex. 3월, 12월 \             코로나 확진자 증가, 거리두기 단계 변화와 비교 )* plot -> pointplot 로 변경* heatmap(corr)    *시간 -> 지역    *요일 -> 월~일    ----------------------------------*ppt 제작* - 주제 선정 동기, 개요, 목적등 * 대중교통이 감소하였고, 그럼 일반 자동차 통행량이 증가하였을까?    - 데이터 수집 방법- 데이터 처리 및 분석    - 분석 방법 : 빈도분석, 기술통계분석, 상관계수분석.    가설 1    데이터 설명 및 인사이트 도출 과정 (아주 간단히) 및 시각화    결론 1    가설 2    데이터 설명 및 인사이트 도출 과정 (아주 간단히) 및 시각화    결론 2    …- 추후 개선 및 느낀점<jupyter_code>pwd
%cd
%cd seoultraffic/
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from matplotlib import pyplot
import seaborn as sns
import matplotlib.font_manager as fm
import missingno as msno #결측데이터 검색
%matplotlib inline
%config InlineBackend.figure_formats = {'png', 'retina'}
# 폰트설정
from matplotlib import font_manager
plt.rcParams["font.family"] = 'NanumGothicCoding'
from matplotlib import rc
rc('font', family="Arial Unicode MS")
### 2019 pub_transpor data road
df1 = pd.read_csv("2019.csv")
### 2020 pub_transpor data road
df2 = pd.read_csv("2020.csv")
### 2019 Traffic data road
#df_2019_url = './data_2019_seoultraffic.csv'
### 2019 Traffic data road
#df_2020_url = './data_2020_seoultraffic.csv'
ddf1 = pd.read_csv("data_2019_seoultraffic.csv")
ddf2 = pd.read_csv("data_2020_seoultraffic.csv")<jupyter_output><empty_output><jupyter_text>Pub_transpor data 2019<jupyter_code>all_traffic_m_2019 = ddf1.pivot_table("total", "month")
all_traffic_m_2019.tail(2)
all_traffic_m_2019.loc[:, "total"] = all_traffic_m_2019.sum(axis=1)
all_traffic_m_2019.tail(2)
all_traffic_m_2020 = ddf2.pivot_table("total", "month")
all_traffic_m_2020.tail(2)
all_traffic_m_2020.loc[:, "tatal"] = all_traffic_m_2020.sum(axis=1)
all_traffic_m_2020.tail(2)<jupyter_output><empty_output><jupyter_text>Pub_transpor data 2020<jupyter_code>all_traffic_m_2019 = ddf1.pivot_table("total", "month", aggfunc=np.sum)
all_traffic_m_2019.tail(2)
all_traffic_m_2020 = ddf2.pivot_table("total", "month", aggfunc=np.sum)
all_traffic_m_2020.tail(2)
all_traffic_r_2019 = ddf2.pivot_table("total", "구", aggfunc=np.sum)
all_traffic_r_2019.tail(2)
all_traffic_r_2020 = ddf2.pivot_table("total", "구", aggfunc=np.sum)
all_traffic_r_2020.tail(2)<jupyter_output><empty_output><jupyter_text>1-1 2019_2020 서울 전체 대중교통량 비교<jupyter_code>y1 = all_traffic_m_2019["total"].sum()
y2 = all_traffic_m_2020["total"].sum()
all_rate_2019 = round(((y2 - y1) / y1 * 100), 2) # 감소량
all_rate_2019
x1 = 0
x2 = 1
#y1 = all_traffic_m_2019["total"].sum() #2019 Total 교통량
#y2 = all_traffic_m_2020["total"].sum() #2020 Total 교통량
y1 = all_traffic_m_2019["total"].sum()
y2 = all_traffic_m_2020["total"].sum()

plt.bar(x1,y1, label='2019 traffic', color='b')
plt.bar(x2,y2, label='2020 traffic', color='g')
plt.legend()
plt.ylim([0,70*1000000000/6])
plt.text(0.17,85*100000000,all_rate_2019,fontsize=20)
plt.text(0.5,85*100000000,"% 감소",fontsize=20)
plt.title("2019_2020 서울 전체 교통량 비교", fontsize = 15)

plt.show()<jupyter_output><empty_output><jupyter_text>1-2 2019_2020 서울 전체 차량 통행량 비교  2-1 2019-2020 월별 서울 교통량 비교<jupyter_code>all_tans_2019 = round(all_traffic_m_2019["total"].mean())
print("2019년 평균 통행량 :", all_tans_2019,"대")
compare_2019 = all_traffic_m_2019[all_traffic_m_2019["total"] > all_traffic_m_2019["total"].mean()]
compare_df_2019 = pd.DataFrame(compare_df_2019, columns=["total"])
compare_df_2019
all_tans_2020 = round(all_traffic_m_2020["total"].mean())
print("2020년 평균 통행량 :", all_tans_2020,"대")
compare_2020 = all_traffic_m_2020[all_traffic_m_2020["total"] > all_traffic_m_2020["total"].mean()]
compare_df_2020 = pd.DataFrame(compare_2020, columns=["total"])
compare_df_2020
X = ["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"]
y1 = all_traffic_m_2019.total
y2 = all_traffic_m_2020.total

plt.figure(figsize=(20, 5))
plt.plot(X,y1, label='2019 traffic(month)', color='b', marker='o')
plt.plot(X,y2, label='2020 traffic(month)', color='g', marker='*')

plt.legend()
plt.title("2019-2020 Traffic Counting", fontsize=20)
plt.axhline(y=all_tans_2019, color='r', linewidth=1)
plt.axhline(y=all_tans_2020, color='r', linewidth=1)

plt.show()<jupyter_output><empty_output><jupyter_text>2-2 2019-2020 월별 차량 통행량 비교  3-0. 요일별 대중 교통량 출력<jupyter_code>df3 = pd.read_csv("2019.csv")
day_pub_traffic_2019 = df3.drop(columns=["시간", "지명", "발생량", "도착량", "월"])
day_pub_traffic_2019
data, weeks = [], ["월", "화", "수", "목", "금", "토", "일"]
for week in weeks:
    data.append(day_pub_traffic_2019[day_pub_traffic_2019["날짜"].str.contains(week)]["count"].sum())
day_pub_traffic_2019 = pd.DataFrame(data=data, index=weeks).reset_index()
day_pub_traffic_2019.columns = ["요일", "count"]
day_pub_traffic_2019
df4 = pd.read_csv("2020.csv")
day_pub_traffic_2020 = df4.drop(columns=["시간", "지명", "발생량", "도착량", "월"])
day_pub_traffic_2020
data, weeks = [], ["월", "화", "수", "목", "금", "토", "일"]
for week in weeks:
    data.append(day_pub_traffic_2020[day_pub_traffic_2020["날짜"].str.contains(week)]["count"].sum())
day_pub_traffic_2020 = pd.DataFrame(data=data, index=weeks).reset_index()
day_pub_traffic_2020.columns = ["요일", "count"]
day_pub_traffic_2020<jupyter_output><empty_output><jupyter_text>3 요일별 대중교통 이용량 비교  3.1.1주말 대중교통 이용량 비교(토,일)<jupyter_code>ddf3 = pd.read_csv("./data_2019_seoultraffic.csv")
day_all_traffic_2019 = pd.DataFrame(ddf3, columns=["요일", "total"])
day_all_traffic_2019
data, weeks = [], ["월", "화", "수", "목", "금", "토", "일"]
for week in weeks:
    data.append(day_all_traffic_2019[day_all_traffic_2019["요일"].str.contains(week)]["total"].sum())
day_all_traffic_2019 = pd.DataFrame(data=data, index=weeks).reset_index()
day_all_traffic_2019.columns = ["요일", "total"]
day_all_traffic_2019
ddf4 = pd.read_csv("./data_2020_seoultraffic.csv")
day_all_traffic_2020 = pd.DataFrame(ddf4, columns=["요일", "total"])
day_all_traffic_2020
data, weeks = [], ["월", "화", "수", "목", "금", "토", "일"]
for week in weeks:
    data.append(day_all_traffic_2020[day_all_traffic_2020["요일"].str.contains(week)]["total"].sum())
day_all_traffic_2020 = pd.DataFrame(data=data, index=weeks).reset_index()
day_all_traffic_2020.columns = ["요일", "total"]
day_all_traffic_2020<jupyter_output><empty_output><jupyter_text>3.1.2 주말 차량 통행량 비교(토,일)<jupyter_code>(np.sum(ytraffic_2020["count"][-2:]) - np.sum(ytraffic_2019["count"][-2:]))\
/ np.sum(ytraffic_2019["count"][-2:]) * 100
X1 = ["2019년"]
X2 = ["2020년"]

y1 = week_2019
y2 = week_2020

plt.bar(X1, y1)
plt.bar(X2, y2)
plt.ylim([300000000, 120*10000000]) 

plt.text(X1, 60*10000000, week_2019, ha="center", fontsize = 20)
plt.text(X2, 60*10000000, week_2020, ha="center" ,fontsize = 20)
plt.title("rate : -10.27.%", fontsize = 20)
plt.show()


plt.show()<jupyter_output><empty_output><jupyter_text>3.2.1 평일 대중교통 이용량 비교(월-금)<jupyter_code>(np.sum(ytraffic_2020["count"][:-2]) - np.sum(ytraffic_2019["count"][:-2]))\
/ np.sum(ytraffic_2019["count"][:-2]) * 100
y1 = sum(ytraffic_2019["count"][:-2])
y2 = sum(ytraffic_2020["count"][:-2])
y1, y2
plt.bar("2019년 평일 교통량", y1)
plt.bar("2020년 평일 교통량", y2)

a = np.sum(ytraffic_2019["count"][:-2])
b = np.sum(ytraffic_2020["count"][:-2])
plt.text("2019년 평일 교통량",80*10000000, a, ha="center", fontsize = 20)
plt.text("2020년 평일 교통량", 80*10000000, b, ha="center", fontsize = 20)
plt.title("-23.57%", fontsize = 20)
plt.show()<jupyter_output><empty_output><jupyter_text>3.2.2 평일 차량통행량 비교(월-금)<jupyter_code>dayofthweek_2020
yy1 = (np.sum(dayofthweek_2019[0:4])+np.sum(dayofthweek_2019[-1:])).values
yy2 = (np.sum(dayofthweek_2020[0:4])+np.sum(dayofthweek_2020[-1:])).values
cc = ((yy2 - yy1) / yy2 ) * 100
plt.bar("2019년 평일 교통량", yy1)
plt.bar("2020년 평일 교통량", yy2)

yy1 = (np.sum(dayofthweek_2019[0:4])+np.sum(dayofthweek_2019[-1:])).values
yy2 = (np.sum(dayofthweek_2020[0:4])+np.sum(dayofthweek_2020[-1:])).values
plt.text("2019년 평일 교통량", 50*10000000, yy1, ha="center", fontsize = 13)
plt.text("2020년 평일 교통량", 50*10000000, yy2, ha="center", fontsize = 13)
plt.title(cc, fontsize = 20)
plt.show()<jupyter_output>/Users/ijiyeong/opt/anaconda3/envs/jiyoung/lib/python3.7/site-packages/matplotlib/text.py:1215: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if s != self._text:<jupyter_text>4.지역별 비교  4.1지역별 대중교통량 비교<jupyter_code>traffic_r_2019.loc[:,'region'] = ['강남구', '강동구', '강북구', '강서구', '관악구', '광진구', '구로구', '금천구', \
                                  '노원구', '도봉구', '동대문구', '동작구', '마포구', '서대문구', '서초구', '성동구', \
                                 '성북구', '송파구', '양천구', '영등포구', '용산구', '은평구', '종로구', '중구', '중랑구' ]

traffic_r_2019.tail(2)
traffic_r_2019['total'].mean()
traffic_r_2019_a = round(traffic_r_2019['total'].mean())
print("2019년 평균 통행량 :", traffic_r_2019_a,"대")
aa = traffic_r_2019[traffic_r_2019 > traffic_r_2019.mean()]
aaa = pd.DataFrame(aa, columns=["total"])
aaa.drop()

aaa
traffic_r_2020.loc[:,'region'] = ['강남구', '강동구', '강북구', '강서구', '관악구', '광진구', '구로구', '금천구', \
                                   '노원구', '도봉구', '동대문구', '동작구', '마포구', '서대문구', '서초구', '성동구', \
                                 '성북구', '송파구', '양천구', '영등포구', '용산구', '은평구', '종로구', '중구', '중랑구' ]

traffic_r_2020.tail(2)
traffic_r_2020['total'].mean()
traffic_r_2020_a = round(traffic_r_2020['total'].mean())
print("2020년 평균 통행량 :", traffic_r_2020_a,"대")
traffic_m_2019.tail()
traffic_r_2019.tail()
dfdf_2019 = traffic_m_2019[traffic_m_2019["total"] > traffic_m_2019["total"].mean()]
dfdfdf_2019 = pd.DataFrame(dfdf_2019, columns=["total"])
dfdfdf_2019
bb = traffic_r_2020[traffic_r_2020["total"] > traffic_r_2020["total"].mean()]
bbb = pd.DataFrame(bb, columns=["total"])
bbb
plt.figure(figsize=(20, 5))

X = ['강남구', '강동구', '강북구', '강서구', '관악구', '광진구', '구로구', '금천구', \
    '노원구', '도봉구', '동대문구', '동작구', '마포구', '서대문구', '서초구', '성동구', \
    '성북구', '송파구', '양천구', '영등포구', '용산구', '은평구', '종로구', '중구', '중랑구' ]

plt.bar(X, traffic_r_2019["total"])
plt.bar(X, traffic_r_2020["total"])


#plt.bar(traffic_r_2019["region"], traffic_r_2019["total"])
#plt.bar(traffic_r_2020["region"], traffic_r_2020["total"])
#plt.legend()
plt.axhline(y=traffic_r_2019['total'].mean(), color='g', linewidth=1) #label="2019")
plt.axhline(y=traffic_r_2020['total'].mean(), color='r', linewidth=1) #label="2020")


plt.show()
#4.2 지역별 차량 교통량 비교
ddf_2019 = traffic_2019
ddf_2019 = ddf_2019.pivot_table("총합","구",aggfunc=np.sum)
ddf_2019 = ddf_2019.reset_index()
ddf_2019.tail()
gein_tans_2019 = round(ddf_2019["총합"].mean())
print("2019년 평균 통행량 :", gein_tans_2019,"대")
traffic_r_2020_a = round(traffic_r_2020['total'].mean())
print("2020년 평균 통행량 :", traffic_r_2020_a,"대")
ddff_2019 = ddf_2019[ddf_2019["총합"] > ddf_2019["총합"].mean()]
ddff_2019
ddf_2020 = traffic_2020
ddf_2020 = ddf_2020.pivot_table("총합","구",aggfunc=np.sum)
ddf_2020 = ddf_2020.reset_index()
ddf_2020.tail()
gein_tans_2020 = round(ddf_2020["총합"].mean())
print("2020년 평균 통행량 :", gein_tans_2020,"대")
ddff_2020 = ddf_2020[ddf_2020["총합"] > ddf_2020["총합"].mean()]
ddff_2020
plt.figure(figsize=(20, 8))
plt.bar(ddf_2019["구"], ddf_2019["총합"])
plt.bar(ddf_2020["구"], ddf_2020["총합"])

#plt.legend()
plt.axhline(y=gein_tans_2019, color='g', linewidth=1) #label="2019")
plt.axhline(y=gein_tans_2020, color='r', linewidth=1) #label="2020")


plt.show()

import seaborn as sns

ddff_2019["연도"] = 2019
ddff_2020["연도"] = 2020
dddfff = pd.concat([ddff_2019, ddff_2020])

x = dddfff["구"]
y = dddfff["총합"]

plt.figure(figsize =(15, 8))
sns.barplot(x=x, y=y, hue=dddfff["연도"])
plt.axhline(y=gein_tans_2019, color='g', linewidth=2) #label="2019"
plt.axhline(y=gein_tans_2020, color='r', linewidth=2) #label="2020"<jupyter_output>/Users/ijiyeong/opt/anaconda3/envs/jiyoung/lib/python3.7/site-packages/ipykernel_launcher.py:3: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  This is separate from the ipykernel package so we can avoid doing imports until
/Users/ijiyeong/opt/anaconda3/envs/jiyoung/lib/python3.7/site-packages/ipykernel_launcher.py:4: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  after removing the cwd from sys.path.
{'fraction_non_alphanumeric': 0.1883148237566393, 'fraction_numerical': 0.10663125704168679, 'mean_word_length': 6.2040579710144925, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 11, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '491052', 'license': 'MIT', 'n_tokens_mistral': 6745, 'n_tokens_neox': 6820, 'n_words': 920, 'path': 'beta_seoultraffic_rev_2.ipynb', 'repo_name': 'JIYOUNGL22/firtst_project', 'size': '12426'}