노트/Python : 프로그래밍(69)
-
[Kaggle] 자전거 수요 예측 분석 (bike-sharing demand prediction)
데이터 다운로드 https://www.kaggle.com/c/bike-sharing-demand/data Bike Sharing Demand Forecast use of a city bikeshare system www.kaggle.com bike data 불러오기 이번 프로젝트는 Kaggle에 있는 공용 자전거 수요 데이터를 학습하여, 각 날짜마다 자전거 수요를 예측해보는 프로젝트에 대해 포스팅하려고 한다. 먼저 트레이닝 데이터와 테스트 데이터를 불러온다. train=pd.read_csv("train.csv", parse_dates=['datetime']) #pare_dates: 날짜 시간으로된 컬럼을 datetime으로 파싱 train.head() test=pd.read_csv("test.csv",p..
2020.04.02 -
[파이썬기초] 주민번호 뒷자리를 별표(*)로 변경하기
data=""" kim 950101-1234567 lee 970202-2345678 """ result=[] for line in data.split("\n"): word_res=[] for word in line.split(" "): if len(word)==14 and word[:6].isdigit() and word[7:].isdigit(): w=word[0:6]+"-"+"*******" word_res.append(w) result.append(" ".join(word_res)) print("\n".join(result))
2020.04.02 -
[파이썬 기초] 데이터 그룹화
데이터 다운로드 : gapminder.tsv https://www.kaggle.com/gbahdeyboh/gapminder#gapminder.tsv Gapminder www.kaggle.com import pandas as pd df=pd.read_csv("gapminder.tsv",sep="\t") 데이터 그룹화 df.year.unique() #year열의 유일한 값 확인 df.head() #년도별 기대수명의 평균 df.groupby('year')['lifeExp'].mean() #년도, 지역별로 기대수명과 gdp갭의 평균 df.groupby(['year','continent'])[['lifeExp','gdpPercap']].mean() # 그룹화한 데이터 갯수 세기 df.groupby('year')[..
2020.04.02 -
[파이썬기초] 데이터 정보 확인 및 참조
데이터 다운로드 : gapminder.tsv https://www.kaggle.com/gbahdeyboh/gapminder#gapminder.tsv Gapminder www.kaggle.com import pandas as pd df=pd.read_csv("gapminder.tsv",sep="\t") 데이터 확인 df.dtypes #각 열의 데이터형식 확인 df.columns # 열이름 확인 df.info() # 각 열의 data갯수, null값, 데이터형식 메모리크기 확인 cdf=df['country'] #지정한 열 참조 cdf.head() type(cdf) # 지정한 열 하나만 참조하여 대입하면 시리즈로 저장됌. subset=df[['country','continent','year']] # 지정한 여..
2020.03.31 -
[Kaggle] TED-Talk 토픽모델링 (Topic modeling)
토픽 모델링 기법은 여러 이야기들의 토픽들을 뽑는 데, 주로 사용할 수 있는 모델링 기법이다. 지난 번 프로젝트 때 데이터 수집 및 전처리를 잘못해서 요상한 결과를 가지고 왔었는데, Kaggle에 잘 정제된 데이터와 분석 방법에 대한 노트북이 있어서 이를 참고하여 포스팅하고자 한다. 데이터 다운로드 아래 kaggle 링크 접속 후, 하단으로 스크롤하여 자막data와 tedtalk meta data를 다운로드 로그인 후, 다운로드 모양의 아이콘을 클릭하면 데이터를 다운로드 할 수 있다. https://www.kaggle.com/adelsondias/ted-talks-topic-models TED-Talks topic models Explore and run machine learning code with ..
2020.03.28 -
[파이썬] 두 점사이의 거리 구하기 코드
# 피타고라스 정리를 이용한, 두 점 사이의 거리 구하기 코드 2차원 공간 import math def pointDist(x1,y1,x2,y2): class Point2D: def __init__(self,x,y): self.x=x self.y=y p1=Point2D(x=x1,y=y1) p2=Point2D(x=x2,y=y2) print("p1:({},{})".format(p1.x, p1.y)) print("p2:({},{})".format(p2.x, p2.y)) dist=math.sqrt(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2)) print(dist) pointDist(30,20,50,40) >> p1:(30,20) >> p2:(50,40) >> 28.284271247461902 3차..
2020.03.28