목록파이썬 (33)
IT 세계의 후아
※ 문자열.isdigit()문자열이 '숫자'로만 구성돼있는지 확인하는 함수따로 chr, ord 함수를 활용하지 않아도 간단하게 풀 수 있음!!# 프로그래머스 lv1 문자열 다루기 기본def solution(s): a = [i for i in s if ord(i)>=48 and ord(i)
금융 데이터를 다뤄보고 싶던 중 Kaggle에서 이미 완료된 대회를 발견했다..!친절하게도 beginner(나같이 다 까먹은 전공자도,,^^)를 위한 코드와 설명이 돼있어서 복습할 겸 수행해보았다. https://www.kaggle.com/code/miingkang/ml-from-the-beginning-to-the-end-for-newbies/notebook ML from the beginning to the end (For newbies🐢)Explore and run machine learning code with Kaggle Notebooks | Using data from multiple data sourceswww.kaggle.com First. Big Picture -🏔To attempt ..

https://hoooa.tistory.com/36 [kaggle]Ubiquant Market Prediction금융 데이터를 다뤄보고 싶던 중 Kaggle에서 이미 완료된 대회를 발견했다..!친절하게도 beginner(나같이 다 까먹은 전공자도,,^^)를 위한 코드와 설명이 돼있어서 복습할 겸 수행해보았다. https://www.hoooa.tistory.com위의 문제를 수행하다가 맞닥뜨린 인덱스 문제..! 찾아보니 Pandas에선 float16 index가 제공이 안 된다..라는 게 포인트여서 어떤 게 float이었나 봤더니 groupby 하고 count하려는 열이 모두 float 형태여서 오류가 난 것..! 그래서 두 열의 데이터 타입 변경해줌으로써 해결~
※ dict() == {}dict([('a', '가'), ('b', '나'), ( , ), ... ])== dict({'a': '가', 'b': '나', '': '', ...})== dict(zip(['a', 'b', ... ], ['가', '나', ... ])) != dict([], []) # 그냥 리스트 두 개만 넣으면 안 됨!!! a_dic.keys(): 키값만 담은 dict_key 객체 returnlist(a_dic.keys())for k in a_dic.keys(): print(k)a_dic.get('키') == a_dic['키'] a_dic.values()a_dic.items(): dict_items[(키, 값), (키, 값), ...] 객체 return# 프로그래머스 lv0 옷가게 ..
round(값): 정수로 반올림round(값, 자리수n): 소수점 n자리수에서 반올림 # 프로그래머스 lv0 두 수의 나눗셈# 테스트 케이스 실패...def solution(num1, num2): return round((num1/num2)*1000) # 수정 후 return int((num1/num2)*1000) ※ int와 roundround: 반올림int: 정수로의 변환 - 소수점 이하 버림 ※ format, f-string"문자열 {1:.2f} ".format(실수1, 실수2) => 실수2를 소수점 둘째자리까지 출력f"문자열 {변수:.3f}" => 변수의 값을 소수점 셋째자리까지 출력 cf) https://blockdmask.tistory.com/534..
set 활용하기!!! a_li = [a, b, c, d]b_li = [b, c, e, f] ※ 합집합list(set(a_li) | set(b_li))== list(set().union(a_li, b_li)) ※ 교집합 ※ 차집합list(set(a_li) - set(b_li)== list(set(a_li).difference(b_li))# 프로그래머스 lv0 글자 지우기# str에서 indices[0,2,6,...] 인덱스 글자들만 빼서 출력하기# 초반 풀이 - 테스트 케이스 에러..def solution(my_string, indices): li = list(set([i for i in range(len(my_string))]).difference(indices))..
※ range()특정 범위로 연속된 정수 생성range(end): 0 ~ (end-1)range(start, end): start ~ (end-1)range(start, end, step): start ~ (end-1), step 간격 # 프로그래머스 lv0 배열 만들기# 1부터 n 사이 k의 배수def solution(n, k): return [k*i for i in range(1, n//k+1)] # return [i for i in range(k,n+1,k)] # 프로그래머스 lv0 짝수의 합def solution(n): return sum([2*i for i in range(n//2+1)]) # return sum([i for i in range(..
※ list comprehension으로 다중 if문 쓰기for i in list: if 조건A: print("a") elif 조건B: print("b") else: print("c")≫ print(["a" if 조건A else "b" if 조건B else "c" for i in list]) # 프로그래머스 lv0 qr code# 초반 풀이def solution(q, r, code): return code[r-1::q] if r>0 else code[r::q-1] # ValueError: slice step cannot be zero # q=1, r=0일 때 오류! # 수정 후 return code[r::q] if r>0 else code if q..