Data Science / Section 1 / Sprint 1 / 20.12.29
WARP UP
What 'Data Scientists' spends the most time doing
1) cleaning and organizing data : 60%
2) collecting data sets : 19%
...
일반적인 데이터(raw data)는 굉장히 정리안되어있고 너저분한 상태
이를 잘 가공한뒤 ML Model에 넣어줘야 잘 작동함
feature engineering 은 데이터를 가공하는데 큰 도움을 준다
Outlier Detection
1) Domain Knowledge : price per sqft > 3500 (3500이하의 값은 무시)
2) Visualization : 도표 등으로 그려서 확인한다
3) Math / Statistics : two standard deviation (표준편차)
Handling missing values
빠진 데이터값을 채운다 (평균값을 활용하여)
One hot encoding
텍스트값을 0과 1 숫자로 바꿔 적용
Feature Engineering is
a process of extracting useful features from raw data using math, statistics and domain knowledge.
Lecture
피쳐 엔지니어링
주어진 데이터를 가공해서 (좋은 데이터로 바꿔서)
효율적으로 학습할수있도록 조합하는 창의적인 작업
DataFrame
행(Row), 열(Column)
df = pd.read_csv('https://dfkljdlfksjlk.csv')
df.dtypes
#각 열값의 형태 (Object , int64 , float64 ...)
문자열(String)
25,970 (str) -> 숫자가 아닌 부분을 제거
25970 (str) -> 문자를 숫자로 형변환
25970 (int)
string replace
https://www.w3schools.com/python/ref_string_replace.asp
Python String replace() Method
Python String replace() Method ❮ String Methods Example Replace the word "bananas": txt = "I like bananas" x = txt.replace("bananas", "apples") print(x) Try it Yourself » Definition and Usage The replace() method replaces a specified phrase with another
www.w3schools.com
testString = '25,970'
testString.replace(',' , '') # , 를 공백으로 바꾼다
int(testString)
as Function
def toInt(string):
return int(string.replace(',',''))
toInt('25,970')
25970
Apply
df['부채총계'] = df['부채총계'].apply(toInt)
df['자본총계'] = df['자본총계'].apply(toInt)
df['자산'] = df['부채총계'] + df['자본총계']
assignment
def toInt(string):
return int(string.replace(',',''))
df['영업이익'] = df['영업이익'].apply(toInt)
df['매출액'] = df['매출액'].apply(toInt)
df['영업이익률2'] = df['영업이익'] / df['매출액'] * 100
#소수점 2까지만 표시하고싶다면
df['영업이익률2'] = np.round(df.영업이익률2,2)
www.python2.net/questions-283016.htm
python - 데이터 프레임 팬더에서 열을 반올림 할 수없는 이유
데이터 프레임에서 열을 반올림하려고합니다. 문제는 숫자를 정렬하지만 소수로 가져 오는 것입니다. 다른 옵션을 시도했습니다 : df['DataFrame column'].apply(np.ceil) df['DataFrame column'].round(decimals=number
www.python2.net
KT&G의 PDR구하기
시가총액
ko.tradingeconomics.com/033780:ks:market-capitalization
KT&G | 033780 - Market Capitalization
KT&G reported 10736.27B in Market Capitalization for its second fiscal quarter of 2020.
tradingeconomics.com
아직도 많이 햇갈리는 파이썬 출력
지정된 함수값과 텍스트를 같이 출력하고 싶을때
print("KT&G의 2018년 PDR은", round(PDR18,2) , "입니다")
print("KT&G의 2019년 PDR은", round(PDR19,2) , "입니다")
String Manipulation
replace 가 아닌 다른 방법으로 특정 문자열 제거
strip 활용하면 된다고 하는데 수많은 오류와 문제를 못풀다가 다른 방법으로 우격다짐으로 해결함
strip(',') 을 활용하고싶었는데 에러발생
#invalid literal for int() with base 10
#could not convert string to float
a = ''.join([c for c in a if c not in (',')])
이방법으로 해결
어떤 원리인지는 모르나 우선 답을 냄
Apply
df2['매출액'] = df2['매출액'].map(lambda x : x.replace(',','')).apply(pd.to_numeric)
[Python] DataFrame의 데이터 변형 메서드
data-make.tistory.com/134
[Python] DataFrame의 데이터 변형 메서드
참고글 : [Python] Pandas - DataFrame [Python] Pandas - DataFrame 관련 메서드 #. 문자열 분리, 결합, 공백 제거 (.split, .join, .strip) # 문자열 분리 : split메서드 pro.EMAIL 0 captain@abc.net 1 swee..
data-make.tistory.com
[Python pandas] DataFrame의 문자열 칼럼을 숫자형으로 바꾸기 : pd.to_numeric(), DataFrame.astype()
[Python pandas] DataFrame의 문자열 칼럼을 숫자형으로 바꾸기 : pd.to_numeric(), DataFrame.astype()
이번 포스팅에서는 Python pandas DataFrame 이나 Series 내 문자열 칼럼을 숫자형으로 변환(how to convert string columns to numeric data types in pandas DataFrame, Series) 하는 2가지 방법을 소개하겠습..
rfriend.tistory.com
TIW
1) Data Frame, series, Object, Character, int, float, str, string, pd, pandas 개념 어렵다
2) for in 활용해서 노가다 말고 영리하게 해결해보기
3) replace 말고 다른방법으로 ',' 지우기
도전 Assignment
기존값을 Na값으로 치환
df['당기순이익(비지배)'][2] = None
stackoverflow.com/questions/13842088/set-value-for-particular-cell-in-pandas-dataframe-using-index
Set value for particular cell in pandas DataFrame using index
I've created a Pandas DataFrame df = DataFrame(index=['A','B','C'], columns=['x','y']) and got this x y A NaN NaN B NaN NaN C NaN NaN Then I want to assign value to particular cell...
stackoverflow.com
결측치 자리에 mean imputation 넣기
우선 mean 값을 구하고
fillna 로 넣기
[파이썬] Pandas 행과 열로 데이터 추출하기: loc[ ], iloc[ ]
판다스에서 데이터를 행과 열로 데이터를 추출하는 방법을 살펴보겠습니다. 몇 가지 기본 문법만 숙지하면 다양한 방식으로 응용할 수 있습니다. 먼저 컬럼 데이터를 추출하는
hogni.tistory.com
'AI월드 > ⚙️AI BOOTCAMP_Section 1' 카테고리의 다른 글
Data Visulaize,plot,seaborn_Day4 (0) | 2021.01.03 |
---|---|
Data Manipulation,concat,merge,melt_Day3 (0) | 2020.12.30 |
25 pandas tricks_Day3(2) (0) | 2020.12.30 |
Feature Engineering,형변환_Day2(2) (0) | 2020.12.30 |
시작,EDA,Data Science_Day1 (0) | 2020.12.28 |
댓글