반응형

Python 4

파이썬 - 파일, 디렉토리

파일의 경로 file = "/content/drive/A/letter.txt" dirname = os.path.dirname(file) basename = os.path.basename(file) print(f'dirname = {dirname}') print(f'basename = {basename}') f-string 포매팅은 파이썬 버전 3.6 부터 사용할 수 있는 따끈따끈한 기능 입니다. 이전에 언급했던, %포매팅과 str.format 방법보다 더 최근에 나온 것 입니다. f-string의 모양은 f와 {}만 알면 됩니다. 문자열 맨 앞에 f를 붙여주고, 중괄호 안에 직접 변수 이름이나 출력하고 싶은것을 바로 넣으면 됩니다. f'문자열 {변수} 문자열' 디렉토리/파일 확인 현재 작업디렉토리 os...

Python 2023.03.07

Pandas

데이터 로드와 저장 1. CSV 파일 로드하기 예제) csv 파일을 editor로 열면 아래와 같이 쉼표로 구분되어 있다. a,b,c,d,e,keyword 1,2,3,4,5,Hello 11,12,13,14,15,Good 21,22,23,24,25,Nice 31,32,33,34,35,Beautiful 41,42,43,44,45,GoGo import pandas as pd filename = "../datasets/example_1.csv" df = pd.read_csv(filename)//dataFrame 형식으로 읽기 tbl = pd.read_table(filename, sep=',')//구분자 넣어줘야 a b c d e keyword 0 1 2 3 4 5 Hello 1 11 12 13 14 15 Goo..

Python 2022.12.09

list/lambda/numpy/pandas/matplotlib

''.join(myList) //list의 item을 합쳐 문자열로 반환한다 //리스트 타입이 숫자인 경우에는 아래와 같이 map(str, 리스트이름)을 사용해서 리스트를 문자열로 합칠 수 있다. alist = list(range(10)) print(alist) s = ''.join(map(str,alist)) map()함수 👉map(f, iterable)은 함수(f)와 반복가능한(iterable) 자료형을 입력받고, 입력받은 자료형의 각 요소를 함수(f)가 수행한 결과를 묶어서 반환하는 함수. ex) list(map(int, l1)) => map 함수의 결과를 list로 묶어주지 않을 경우 객체로 변환된 위치만 반환 l1 = [2, 5, 6, 7, 8] new_list = list(map(str, l1..

Python 2022.02.02
반응형