Exemple #1
0
class CCTVModel:
    def __init__(self):
        self.dr = DataReader()

    def hook_process(self):
        print('----------------1.cctv 파일로 DF 생성---------------')
        self.get_cctv()

    def get_cctv(self):
        self.dr.context = './data/'
        self.dr.fname = 'cctv_in_seoul.csv'
        cctv = self.dr.csv_to_dframe()
        #print(cctv.columns)#Index(['기관명', '소계', '2013년도 이전', '2014년', '2015년', '2016년'], dtype='object')
        self.dr.fname = 'population_in_seoul.xls'
        pop = self.dr.xls_to_dframe(2, 'B,D,G,J,N')
        #print(pop.columns)#Index(['자치구', '계', '계.1', '계.2', '65세이상고령자'], dtype='object')
        cctv.rename(columns={cctv.columns[0]: '구별'}, inplace=True)
        pop.rename(columns={
            pop.columns[0]: '구별',
            pop.columns[1]: '인구수',
            pop.columns[2]: '한국인',
            pop.columns[3]: '외국인',
            pop.columns[4]: '고령자'
        },
                   inplace=True)

        #pop.drop([0],True)
        #print(pop['구별'].isnull())
        pop.drop([26], inplace=True)  #null 인 데이타 행 삭제하기
        #컬럼추가
        pop['외국인비율'] = pop['외국인'] / pop['인구수'] * 100
        pop['고령자비율'] = pop['고령자'] / pop['인구수'] * 100

        cctv.drop(['2013년도 이전', '2014년', '2015년', '2016년'], 1, inplace=True)
        cctv_pop = pd.merge(cctv, pop, on='구별')  #구별 컬럼명으로 cctv와 pop합치기
        #상관관계 보기
        cor1 = np.corrcoef(cctv_pop['고령자비율'], cctv_pop['소계'])
        cor2 = np.corrcoef(cctv_pop['외국인비율'], cctv_pop['소계'])

        print('고령자 비율과 CCTV위 상관계수 {}\n외국인 비율과 CCTV위 상관계수 {}'.format(
            cor1, cor2))
        '''
        상관관계가 없는 경우  feature를 제거하자
        
        r이 -1.0과 -0.7 사이이면, 강한 음적 선형관계,
        r이 -0.7과 -0.3 사이이면, 뚜렷한 음적 선형관계,
        r이 -0.3과 -0.1 사이이면, 약한 음적 선형관계,
        r이 -0.1과 +0.1 사이이면, 거의 무시될 수 있는 선형관계,
        r이 +0.1과 +0.3 사이이면, 약한 양적 선형관계,
        r이 +0.3과 +0.7 사이이면, 뚜렷한 양적 선형관계,
         r이 +0.7과 +1.0 사이이면, 강한 양적 선형관계
        고령자비율 과 CCTV 상관계수 [[ 1.         -0.28078554] 약한 음적 선형관계
                                   [-0.28078554  1.        ]]
        외국인비율 과 CCTV 상관계수 [[ 1.         -0.13607433] 거의 무시될 수 있는
                                   [-0.13607433  1.        ]]
        
        '''
        cctv_pop.to_csv('./saved_data/cctv_pop.csv')
Exemple #2
0
class CCTVModel:
    def __init__(self):
        self.dr = DataReader()

    def hook_process(self):
        print('----------------1. cctv 파일 DF 생성--------------------')
        self.get_cctv()

        #cctv정보파일 읽어오기
    def get_cctv(self):
        self.dr.context = './data/'
        self.dr.fname = 'cctv_in_seoul.csv'
        cctv = self.dr.csv_to_dframe()
        # 인덱스 확인을 위한 출력문 print(cctv.columns)
        print(cctv.columns)
        # print(cctv) -> 제대로 df로 불러들였는지 확인용
        self.dr.fname = 'pop_in_seoul.xls'
        pop = self.dr.xls_to_dframe(2, 'B,D,G,J,N')
        # B, D, G, J, N 에 있는 것만 불러오기
        # print(pop) -> 제대로 df로 불러들였는지 확인용
        # 인덱스 확인을 위한 출력문 print(pop.columns)
        print(pop.columns)
        cctv.rename(columns={cctv.columns[0]: '구별'}, inplace=True)
        #inplace -> 원본을 바꾸라는 것
        pop.rename(columns={
            pop.columns[0]: '구별',
            pop.columns[1]: '인구수',
            pop.columns[2]: '한국인',
            pop.columns[3]: '외국인',
            pop.columns[4]: '고령자'
        },
                   inplace=True)
        #  pop.drop([0], True)  #1행 삭제
        #        print(pop['구별'].isnull()) #null값 있는지 확인 -> 26번째에서 True 라고 나옴. 26번째가 null값이라는 뜻 -> 삭제필요
        pop.drop([26], inplace=True)  # 27행 삭제
        pop['외국인비율'] = pop['외국인'] / pop['인구수'] * 100
        pop['고령자비율'] = pop['고령자'] / pop['인구수'] * 100

        cctv.drop(['2013년도 이전', '2014년', '2015년', '2016년'], 1,
                  inplace=True)  #연도별정보를 삭제하고 현재자료만 사용
        cctv_pop = pd.merge(cctv, pop,
                            on='구별')  #cctv와 pop이라는 df를 [구별]이라는 컬럼명에 맞게 병합
        cor1 = np.corrcoef(cctv_pop['고령자비율'], cctv_pop['소계'])
        cor2 = np.corrcoef(cctv_pop['외국인비율'], cctv_pop['소계'])

        print('고령자비율과 cctv의 상관계수 {}  \n'
              '외국인비율과 cctv의 상관계수 {}'.format(cor1, cor2))

        # 추출한 데이터를 별도의 디렉토리에 저장
        cctv_pop.to_csv('./saved_data/cctv_pop.csv')
Exemple #3
0
class CCTVModel:
    def __init__(self):
        self.dr = DataReader()

    def hook_process(self):
        print("-------1.cctv 파일 df 생성--------")
        self.get_cctv()

    def get_cctv(self):
        self.dr.context = "./data/"

        #setter의 메소드명과 일치해야 한다.
        #@fname.setter
        #def fname(self, fname):
        self.dr.fname = 'cctv_in_seoul.csv'
        cctv = self.dr.csv_dframe()
        #print(cctv)
        #print(cctv.columns)
        self.dr.fname = "population_in_seoul.xls"
        pop = self.dr.xls_to_dframe(2, "B,D,G,J,N")
        #print(pop)
        #print(pop.header())
        #print(pop.columns)
        cctv.rename(columns={cctv.columns[0]: "구 별"}, inplace=True)
        pop.rename(columns={
            pop.columns[0]: "구 별",
            pop.columns[1]: "인구수",
            pop.columns[2]: "한국인",
            pop.columns[3]: "외국인",
            pop.columns[4]: "고령인"
        },
                   inplace=True)
        #pop.drop([0], True)
        print(pop["구 별"].isnull())
        pop.drop([26], inplace=True)
        pop["외국인비율"] = pop["외국인"] / pop["인구수"] * 100
        pop["고령자비율"] = pop["고령인"] / pop["인구수"] * 100
        #pop.drop([26], inplace=True)

        cctv.drop(["2013년도 이전", "2014년", "2015년", "2016년"], 1, inplace=True)
        cctv_pop = pd.merge(cctv, pop, on="구 별")
        #상관관계를 찾는것
        #가설을 세운 후 증명하는 과정
        cor1 = np.corrcoef(cctv_pop["고령자비율"], cctv_pop["소계"])
        cor2 = np.corrcoef(cctv_pop["외국인비율"], cctv_pop["소계"])

        #가공된 데이터 다시 저장
        cctv_pop.to_csv("./saved_data/cctv_pop.csv")
Exemple #4
0
class CCTVModel:
    def __init__(self):
        self.dr = DataReader()

    def hook_process(self):
        print('--------1.CCTV 파일로 DF 생성 --------------')
        self.get_cctv()

    def get_cctv(self):
        self.dr.context = './data/'
        self.dr.fname = 'cctv_in_seoul.csv'
        cctv = self.dr.csv_to_dframe()
        self.dr.fname = 'population_in_seoul.xls'
        pop = self.dr.xls_to_dframe(2, 'B,D,G,J,N')

        print(cctv.columns)
Exemple #5
0
class CCTVModel:
    def __init__(self):
        self.dr = DataReader()

    def hook_process(self):
        print('------------------ 1. CCTV 파일로 DF 생성 -------------------')
        self.get_cctv()

    def get_cctv(self):
        self.dr.context = './data/'

        self.dr.fname = 'cctv_in_seoul.csv'
        cctv = self.dr.csv_to_dframe()

        self.dr.fname = 'pop_in_seoul.xls'
        pop = self.dr.xls_to_dframe(2, 'B, D, G, J, N' )

        cctv.rename(columns={cctv.columns[0] : '구별'}, inplace=True)
        pop.rename(columns={
            pop.columns[0]: '구별',
            pop.columns[1]: '인구수',
            pop.columns[2]: '한국인',
            pop.columns[3]: '외국인',
            pop.columns[4]: '고령인'
        }, inplace=True)

        #pop.drop([0], True)
        # null값 여부 확인
        #print(pop['구별'].isnull()) 
        pop.drop([26], inplace=True)

        pop['외국인비율'] = pop['외국인'] / pop['인구수'] * 100
        pop['고령자비율'] = pop['고령인'] / pop['인구수'] * 100

        cctv.drop(['2013년도 이전', '2014년', '2015년', '2016년'], 1, inplace=True)
        cctv_pop = pd.merge(cctv, pop, on='구별')

        cor1 = np.corrcoef(cctv_pop['고령자비율'], cctv_pop['소계'])
        cor2 = np.corrcoef(cctv_pop['외국인비율'], cctv_pop['소계'])

        print(f'고령자비율과 CCTV의 상관계수 {cor1} \n 외국인비율과 CCTV의 상관계수 {cor2}')

        cctv_pop.to_csv('./saved_data/cctv_pop.csv')
        '''
class CCTVModel:
    def __init__(self):
        self.dr = DataReader()

    def hook_process(self):
        print('---------- 1. cctv 파일 df 생성 ----------')
        self.get_cctv()

    def get_cctv(self):
        self.dr.context = './data/'
        self.dr.fname = 'cctv_in_Seoul.csv'
        cctv = self.dr.csv_to_dframe()
        #print(cctv.columns)

        self.dr.fname = 'pop_in_seoul.xls'
        pop = self.dr.xls_to_dframe(2, 'B,D,G,J,N') #엑셀에서 해당 컬럼만 가져오겠다
        #print(pop.columns)

        cctv.rename(columns={cctv.columns[0]: '구별'}, inplace=True)
        pop.rename(columns={
            pop.columns[0]: '구별',
            pop.columns[1]: '인구수',
            pop.columns[2]: '한국인',
            pop.columns[3]: '외국인',
            pop.columns[4]: '고령자',
        }, inplace=True)
        #pop.drop([0], True)
        print(pop['구별'].isnull())
        pop.drop([26], inplace=True)
        pop['외국인비율'] = pop['외국인'] / pop['인구수'] * 100
        pop['고령자비율'] = pop['고령자'] / pop['인구수'] * 100

        cctv.drop(['2013년도 이전', '2014년', '2015년', '2016년'], 1, inplace=True)
        cctv_pop = pd.merge(cctv, pop, on='구별') #합쳐진 결과값

        cor1 = np.corrcoef(cctv_pop['고령자비율'], cctv_pop['소계'])
        cor2 = np.corrcoef(cctv_pop['외국인비율'], cctv_pop['소계'])
        print('고령자비율과 CCTV의 상관계수 {} \n'
              '외국인비율과 CCTV의 상관계수 {} '.format(cor1,cor2))

        cctv_pop.to_csv('./saved_data/cctv_pop.csv')


        """
class CCTVModel:
    def __init__(self):
        self.dr = DataReader()
    def hook_process(self):
        print('-'*12,'1. CCTV 파일로 DF 생성','-'*12)
        self.get_cctv()

    def get_cctv(self):
        self.dr.context = './data/'
        self.dr.fname = 'cctv_in_seoul.csv'
        cctv = self.dr.csv_to_dframe()
        print('dr의 type은 ->',type(self.dr))
        print('cctv_columns ->',cctv.columns)
        self.dr.fname='pop_in_seoul.xls'
        pop = self.dr.xls_to_dframe(2,'B,D,G,J,N')
        print('pop_columns ->',pop.columns)
        cctv.rename(columns={cctv.columns[0]: '구별'}, inplace = True)
        print('cctv의 type은 ->',type(cctv))
        pop.rename(columns={
            pop.columns[0]:'구별',
            pop.columns[1]:'인구수',
            pop.columns[2]:'한국인',
            pop.columns[3]:'외국인',
            pop.columns[4]:'고령인',
        },inplace=True)
        # pop.drop([0],True)
        # print(pop['구별'].isnull())# null값 확인하는 방법
        pop.drop([26],inplace=True)
        pop['외국인비율'] = pop['외국인'] / pop['인구수'] * 100
        pop['고령인비율'] = pop['고령인']/pop['인구수']*100

        cctv.drop(['2013년도 이전','2014년', '2015년', '2016년'], 1, inplace = True)
        cctv_pop = pd.merge(cctv,pop,on='구별')
        cor1 = np.corrcoef(cctv_pop['고령인비율'],cctv_pop['소계'])
        cor2 = np.corrcoef(cctv_pop['외국인비율'],cctv_pop['소계'])

        cctv_pop.to_csv('./saved_data/cctv_pop.csv')

        print('고령자비율 cctv의 상관계수 {0}\n'
              +'외국인비율과 cctv의 상관계수 {1}'.format(cor1,cor2))
        '''