일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- dendrogram
- IN
- elbow method
- 반복문
- list
- pandas
- Python
- string
- append()
- count()
- 최댓값
- analizer
- Dictionary
- function
- 최솟값
- 덴드로그램
- matplotlib
- del
- hierarchical_clustering
- numpy
- 분류 결과표
- wcss
- nan
- sklearn
- Machine Learning
- DataAccess
- DataFrame
- data
- len()
- insert()
- Today
- Total
목록Python/Basic (37)
개발공부

MySQL에 만들어져 있는 recipe_db 가 있다. 이 DB에 대한 접속을 Python 코드로 하는 방법은 아래와 같다. 먼저 MySQL에서 recipe_db에만 접속할 수 있는 user를 먼저 만들자. use mysql; create user 'recipe_user'@'%' identified by 'recipe1234'; grant all on recipe_db.* to 'recipe_user'@'%'; 그 후에 Visual Studio Code에서 recipe_db에 접속하는 방법은 아래와 같다. 아래 라이브러리를 설치한다. pip install mysql-connector-python DBMS에 연결하는 함수 import mysql.connector def get_connection() : c..

파이썬에서 압축파일을 푸는 코드는 아래와 같다. import zipfile zip_ref = zipfile.ZipFile('압축파일경로') zip_ref.extractall('압축을 풀 경로') zip_ref.close() 예제 tmp폴더의 horse-or-human.zip 파일의 압축을 풀어 tmp폴더에 horse-or-human 폴더를 생성한 후 저장하기 import zipfile zip_ref = zipfile.ZipFile('/tmp/horse-or-human.zip') zip_ref.extractall('/tmp/horse-or-human') zip_ref.close()

1. 구글 클라우드의 MAPS API 페이지로 이동한다. https://cloud.google.com/maps-platform/?hl=ko Google Maps Platform - Location and Mapping Solutions Create real world and real time experiences for your customers with dynamic maps, routes & places APIs from Google Maps Platform’s location solutions. mapsplatform.google.com 2. 콘솔로 이동 => Geocoding API 선택 => 사용자인증정보 에서 API 키 생성 이제 받은 API KEY를 가지고 원하는 장소의 위치(위도, 경도) ..

relativedelta를 이용하면 날짜의 연산이 가능하다. from dateutil.relativedelta import relativedelta 예제 1. 현재 시간에서 26일 뒤는 언제인가 ? >>> today = datetime.today() >>> print(today) 2022-04-27 18:25:50.196321 >>> goal_day = today + relativedelta(days = +26) >>> print(goal_day) 2022-05-23 18:25:50.196321 2. 현재시간에서 1년 3개월 5일 7시간 후의 시간은 ? >>> today = datetime.today() >>> print(today) 2022-04-27 18:25:50.196321 >>> goal_day..

dateutil.parser의 parse를 이용하면 문자열로 되어있는 날짜를 파이썬이 계산할 수 있도록 변경이 가능하다. from dateutil.parser import parse 기본 사용법은 아래와 같다. >>> date_str = '2022-05-08' >>> someday = parse(date_str) >>> someday datetime.datetime(2022, 5, 8, 0, 0) >>> someday.weekday() 6 >>> parse('2022/06/30') datetime.datetime(2022, 6, 30, 0, 0)

파이썬의 내장 모듈인 time 모듈은 UTC(GMT+0) 기준으로 1970년 1월 1일 0시 0분 0초부터의 경과 시간을 나타내는데 흔히 timestamp라고 불리기도 합니다. UTC 현재시각 time.gmtime()으로 알 수 있다. >>> import time >>> time.gmtime() time.struct_time(tm_year=2022, tm_mon=4, tm_mday=27, tm_hour=9, tm_min=10, tm_sec=56, tm_wday=2, tm_yday=117, tm_isdst=0) local 시각 - 우리나라 기준 시각 time.localtime()으로 알 수 있다. >>> import time >>> time.localtime() time.struct_time(tm_year..

파이썬에서는 datetime 모듈을 통해 날짜와 시간을 처리할 수 있다. 날짜관련은 datetime의 date를 통해 처리할 수 있다. from datetime import date 날짜다루기 기본적으로 날짜를 선언하는 것은 date() 를 통해서 할 수 있다. >>> some_day = date(2022, 5, 8) >>> print(some_day) 2022-05-08 이렇게 만든 some_day의 타입은 datetime.date 이다. >>> type(some_day) datetime.date 이렇게 만들어진 some_day의 년, 월, 일 을 알 수 있는데, 이는 year, month, day로 확인 할 수 있다. >>> some_day.year 2022 >>> some_day.month 5 >>..

랜덤(Random) 라이브러리(함수들의 집합)는 random을 import하여 사용할 수 있다. import random 랜덤(Random) 라이브러리의 함수 랜덤라이브러리의 함수는 random.함수이름() 과 같은식으로 사용할 수 있다. random.random() - 0 ~ 1 사이의 실수 값을 무작위로 가져온다. >>> random.random() 0.7000956306402929 random.randint(num1, num2) - num1 이상 num2 이하의 정수형 난수를 얻는다. >>> random.randint(100, 500) 432 random.uniform(num1, num2) - num1 이상 num2 이하의 실수형 난수를 얻는다. >>> random.uniform(1, 6) 3.94..

List Comprehension - 원본 리스트를 가지고, 다른 리스트를 만드는 방법이다. - for, while 없이 loop를 실행시키는 아름다운 방법이다. 예제 아래 for 문으로 만든 각리스트의 숫자를 7씩 뺀 리스트를 만드는 예제가 있다. >>> score_list = [ 88, 76, 56, 91, 68 ] >>> new_list = [] >>> for data in score_list : >>> new_list.append( data - 7 ) >>> new_list [81, 69, 49, 84, 61] 이를 list comprehension을 이용하면 아래와 같은 식으로 표현할 수 있다. >>> score_list = [ 88, 76, 56, 91, 68 ] >>> new_list = [..

Lambda(람다) Function - Lambda function 은 anonymous function 이다. 즉 함수 이름이 없다. - Lambda functions 은 주로 filter(), map() , reduce() 함수와 함께 사용된다. - 파라미터는 많아도 상관없지만, 연산은 딱 한줄이어야 한다. 기본 표현식 lambda 매개변수 : 표현식 람다는 위와 같은 식으로 표현할 수 있다. 예제 >>>def pow_some(number) : >>> return number ** 2 >>> pow_some(3) 9 위와 같은 함수와 같은 기능을 하는 람다식을 만들어 볼 수 있다. >>> pow_some = lambda number :number ** 2 >>> pow_some(3) 9 위와 같이 하..