본문 바로가기
python/numpy

숫자를 6자리 코드로 만들기

by Falto 2020. 11. 6.
★ 엑셀을 판다스로 읽으면, 코드가 숫자로 바뀐다. 이것을 다시 6자리 종목코드로 미리 바꿔주는 것이 좋다.
        maxrow = df.shape[0]
        for i in range(maxrow):
            code = df.loc[i, '종목코드']
            str_code = ''
            if str(type(code)) == "<class 'int'>" or str(type(code)) == "<class 'numpy.int64'>":
                str_code = str(code)
                str_code = str_code.zfill(6)
            if str(type(code)) == "<class 'str'>":
                str_code = code
                str_code = str_code.zfill(6)
            df.loc[i, '종목코드'] = str_code
        return df


'python > numpy' 카테고리의 다른 글

rand  (0) 2021.08.03
linspace vs arange  (0) 2020.11.01

댓글