Python 문법 39

[상관관계차트] plt.scatter() & sb.regplot()

Matplotlib 분포도 그리기 : 변수간의 관계 plt.scatter(data=cars, x='displ', y='comb') plt.xlabel('Displacement (L)') plt.ylabel('Combined Fuel Eff(mpg)') plt.title('Disple vs comb ') plt.show() Matplotlib 상관관계 분석하기 regression : 데이터에 fitting 한다 : 기울기 추가 sb.regplot(data=cars, x='displ', y='comb') plt.xlabel('Displacement (L)') plt.ylabel('Combined Fuel Eff(mpg)') plt.title('Disple vs comb ') plt.show()

구글맵 api-Geocoding API 설정하는 방법

# 1. 구글에 주소정보를 받기 위한 API Key 를 얻습니다.# 2. 우리가 짜는 파이썬 코드에서, API를 호출하기 위한 라이브러리가 필요. 라이브러리를 설치.# 2-1 Anaconda Prompt를 실행합니다.# 2-2 라이브러리 인스톨을 위한 명령어를 수행합니다. pip install googlemaps 구글 클라우드의 MAPS API 페이지로 이동하여, API 키를 생성합니다.https://cloud.google.com/maps-platform/?hl=ko콘솔로 이동 => Geocoding API 선택 => 사용자인증정보 에서 API 키 생성 구글 맵스를 사용해서 경찰서의 위치(위도, 경도) 정보를 받아온다import googlemaps gmaps_key = "AIzaSyCRNpyrML6AAW..

[reshape, values.reashape] 시리즈를 2차원으로 차원변경할때 주의할점.

오류해결) X와 y의 차원이 같지 않으면 피처스케일링 학습시에 오류가 생긴다. X.shape (500, 5) y.shape (500,) y 0 35321.45877 1 45115.52566 2 42925.70921 3 67422.36313 4 55915.46248 ... 495 48901.44342 496 31491.41457 497 64147.28888 498 45442.15353 499 45107.22566 Name: Car Purchase Amount, Length: 500, dtype: float64 y.values array([35321.45877, 45115.52566, 42925.70921, 67422.36313, 55915.46248, 56611.99784, 28925.70549, 4743..

[Dates and times](3) : pd.DatetimeIndex(), pd.date_range(), pd.timedelta_range()

시작일과 종료일을 세팅하면 알아서 날짜를 채워준다. pd.date_range('2021-11-12', '2021-12-29' ) DatetimeIndex(['2021-11-12', '2021-11-13', '2021-11-14', '2021-11-15', '2021-11-16', '2021-11-17', '2021-11-18', '2021-11-19', '2021-11-20', '2021-11-21', '2021-11-22', '2021-11-23', '2021-11-24', '2021-11-25', '2021-11-26', '2021-11-27', '2021-11-28', '2021-11-29', '2021-11-30', '2021-12-01', '2021-12-02', '2021-12-03', '20..

[Dates and times](2) : pd.to_datetime(), pd.to_timedelta()

Typed arrays of times: NumPy's 'datetime64' import pandas as pd 문자열을 datetype으로 변경 dates = ['2021-01-04' , '2021-01-07','2021-01-08', '2021-01-22'] pd.to_datetime(dates) # 문자열일 경우 바로 실행가능 DatetimeIndex(['2021-01-04', '2021-01-07', '2021-01-08', '2021-01-22'], dtype='datetime64[ns]', freq=None) dates2 = ['2021/01/04' , '2021/01/07','2021/01/08', '2021/01/22'] pd.to_datetime(dates2) DatetimeIndex(..