728x90

Coding Exercise 88

[PANDAS] DataFrame -> CSV 파일로 저장하기

DataFrame을 CSV 파일로 저장하는 방법 New_df.to_csv('파일명or파일경로') New_df.to_csv('파일명or파일경로', encoding='cp949') ## 한글이 포함된 경우 엑셀을 위한 인코딩 CSV 파일을 DataFrame으로 불러오는 방법 readed_df=pd.read_csv('파일명 or 파일경로') readed_df=pd.read_csv('파일명 or 파일경로', encoding='cp849', index_col=0) #encoding 지정하여 한글이 포함된 파일 불러오기 index_col 값이 없으면 모두 column 값으로 입력된다. index는 임의값(0,1,2,...) 으로 정의된다

Machine Learning 2021.08.15

[백준 #9663] N-Queen - 파이썬 (python)

문제를 보자마자 무슨 뜻인지는 알겠는데 구체적으로 어떻게 구현을 해야 할 지 너무 막막했다. 백트래킹 알고리즘에서 아주 유명한 알고리즘이라 다른 블로그를 참고하여서 이해했다. def nqueen(sol,N): global count if len(sol)==N: count+=1 return 0 candidate=list(range(N)) for i in range(len(sol)): if sol[i] in candidate: candidate.remove(sol[i]) distance=len(sol)-i if sol[i]+distance in candidate: candidate.remove(sol[i]+distance) if sol[i]-distance in candidate: candidate.remo..

Baekjoon Case 2021.08.15

[백준 #15652] N과 M(4) - 파이썬(python)

비내림차순이라고 하는 이유가 같은 수가 있어서 그런거였구나.. from itertools import combinations_with_replacement N,M=map(int,input().split()) numlist=map(str,range(1,N+1)) setlist=list(combinations_with_replacement(numlist,M)) print('\n'.join(list(map(' '.join,setlist)))) itertools 라이브러리에서 조합과 순열 관련한 함수들을 모조리 다 써보는 문제였군. 이 라이브러리를 몰랐다면,, 아마 답답함에 몸부림 쳤을 듯 싶다. 이번에는 combinations_with_replace(arr,n) 함수를 써서 풀었다. 아주 유익한 라이브러리인 ..

Baekjoon Case 2021.08.14

[백준 #15651] N과 M(3) - 파이썬(python)

중복을 포함한 조합을 출력하는 문제 역시나 itertools 라이브러리의 product 함수를 활용하면 바로 나온다. from itertools import product N,M=map(int,input().split()) numlist=map(str,range(1,N+1)) setlist=sorted(list(product(numlist,repeat=M))) print('\n'.join(list(map(' '.join,setlist)))) 예전에는 어떻게든 내 힘으로 풀려고 했었는데, (아는것도 없으면서..) 지금은 내가 필요한 function을 가지고 있는 라이브러리를 구글링해서 푸니까 훨씬 좋은 것 같다. (어차피 쓰라고 만들어 놓은 라이브러리니까..)

Baekjoon Case 2021.08.14

[백준 #15649] N과 M(1) - 파이썬(python)

처음엔 굉장히 쉬워보였는데, M값을 왜 받아야 하지.. 라고 생각했는데 역시나 필요했다. 재귀함수를 써 볼까 생각도 했는데 왠지 파이썬에는 이미 구현되어 있는 함수가 있을 것 같아서 열심히 구글링을 했다. from itertools import permutations N,M=map(int,input().split()) numlist=[i for i in range(1,N+1)] setlist=list(permutations(numlist,M)) for i in range(len(setlist)): for j in range(M): print(setlist[i][j],end=' ') print() 재귀함수를 구현 해 볼까 했는데 굉장히 골치가 아파보여서 굳이..? 라는 생각이 들었다. 있는 것을 잘 활용하..

Baekjoon Case 2021.08.13
728x90