목록Language (25)
언빌리버블티

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 1: invalid start byte. Pandas 에서 read_csv 등 데이터 파일을 불러올 때 발생하는 오류이다. 불러오는 csv , txt 파일 등의 encoding 방식과 python 의 encoding 방식이 다르면 해당 에러가 발생하기 때문에 인코딩을 맞춰 불러와줘야 한다. from glob import glob raw = pd.read_csv(file_name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 1: invalid start byte encoding 값을 cp949 로 적용시켜..

AttributeError: 'str' or 'list' object has no attribute 'astype' 다음 데이터에서 기간의 연도를 split을 통해 나누고 , int 형식으로 바꾼 뒤 새로운 파생 변수를 만들고자 하였다. split()으로 반환한 결과값에 대해 astype() 메서드가 적용되지 않고 에러가 나서 그 이유와 해결 방법을 알아보았다. df. astype() df.astype의 경우 데이터 프레임의 데이터 타입을 바꾸는 함수이다. 따라서 리스트와 문자열을 반환하는 split에 바로 적용해주게 되면 error가 발생한다. df_first_melt['기간'].str.split('년')[0].astype(int) AttributeError: 'list' object has no at..
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed This behaviour is the source of the following dependency conflicts. requests 2.23.0 requires urllib3!=1.25.0,!=1.25.1,=1.21.1, but you have urllib3 1.26.12 which is incompatible. Successfully installed async-generator-1.10 exceptiongroup-1.0.0rc9 h11-0.14.0 outcome-1.2.0 selenium-4.5.0 sniff..

Pandas 시리즈 접근자 dtype에 따라 시리즈에 접근할 수 있는 다양한 접근자를 제공하고 있다. 시리즈 내에서 특정 데이터 유형에만 적용되는 별도의 네임스페이스이다. Data Type Accessor Datetime dt String str Categorical cat Sparse sparse Datetime properties Series.dt.date Returns numpy array of python datetime.date objects. Series.dt.time Returns numpy array of datetime.time objects. Series.dt.timetz Returns numpy array of datetime.time objects with timezones. Ser..

요소가 df 또는 Series 에 포함되는지 검사 pd.isin() 칼럼이 list의 값들을 포함하고 있는지를 검사 DataFrame 컬럼에서 어떤 list의 값을 포함하고 있는 것만 걸러낼 때 유용하게 사용된다. DataFrame.isin(values) 활용 예시 # isin 을 사용해 리스트로 여러 값을 찾아오기 # "거주구"가 "강남구", "서초구", "송파구" 인 데이터만 찾기 df[df["거주구"].isin(["강남구", "서초구", "송파구"])].head() Reference pandas.DataFrame.isin — pandas 1.5.0 documentation The result will only be true at a location if all the labels match. If ..

Pandas 데이터를 숫자 형식으로 변환하기 pd.to_numeric() 숫자형식으로 변경시킬 대상으로 스칼라값, list, tuple, Series 등을 지정 pandas.to_numeric(arg, errors='raise', downcast=None) errors 파라미터 ' ignore ' : 만약 숫자로 변경할 수 없는 데이터라면 숫자로 변경하지 않고 원본 데이터를 그대로 반환 ' coerce ' : 만약 숫자로 변경할 수 없는 데이터라면 기존 데이터를 지우고 NaN으로 설정하여 반환 ' raise ' : 만약 숫자로 변경할 수 없는 데이터라면 에러 발생 후 코드 중단 downcast 파라미터 INT8 , Float32 형식 등을 지정해줄 수 있다 . 활용 예시 문자형인 숫자와 숫자가 섞인 경우..

데이터프레임 조건 탐색 및 대치 메서드 .where() & np.where() 비교 series.where() : 판다스 Series 객체의 함수 Series.where(조건, other=_NoDefault.no_default, inplace=False, axis=None, level=None, errors=_NoDefault.no_default, try_cast=_NoDefault.no_default) Series 객체에 대한 조건문과 거짓 값을 대체할 값 두 가지를 입력받는다. pandas의 메서드는 아님 ! 시리즈 객체의 함수 조건문의 참 값에 대해서는 Series값이 그대로 들어가게 된다. df.where(df['접촉력'] == '해외유입',False)['접촉력'] 연번 218646 False 2..

Pandas 데이터프레임 행 방향 누적값 계산 pd.cumsum / pd.cumprod cumsum / cumprod메서드를 사용해서 행/열의 누적합/누적곱을 구할 수 있다. 위에서부터 아래로 한줄씩 덧셈/곱셈을 누적한다. pd.cumsum() DataFrame.cumsum(axis=None, skipna=True, args, kwargs) axis : 누적합/ 누적곱을 적용할 축 기준을 설정 skipna : 결측치를 무시할 지 여부 설정 pd.cumprod() DataFrame.cumprod(axis=None, skipna=True, args, kwargs) 활용 예시 서울시 코로나19 공공데이터 활용 2020년 1월부터 2021년 12월 까지의 확진자 수 / 누적 확진자 수의 변화 그래프 시각화 df..