728x90

pandas 8

pandas에서 describe() 사용하면 전체 숫자가 안나올 때

전체 숫자를 확인하고 싶지만 아래와 같이 나오는 경우가 있다. a b c 0 1.005544e+05 1.226455e+04 2.643200e+03 1 5.542502e+03 7.135909e+03 5.435605e+02 이 경우 아래와 같은 코드를 먼저 입력하면 전체 숫자를 볼 수 있다. pd.set_option('float_format', '{:.2f}'.format) a b c 0 10055 12264 2643 1 5542 7135 543 참고 stackoverflow.com/questions/41328633/how-do-i-print-entire-number-in-python-from-describe-function How do I print entire number in Python from de..

python에서 pandas dataframe에서 컬럼의 text가 모두 안보이는 경우

컬럼 값이 길경우 ....으로 줄여서 나오는 경우가 있다. 이 때는 아래와 같은 옵션을 데이터 조회 전에 실행하면 된다. 두 번째 파라미터의 -1은 노출할 텍스트 수의 제한이 없음을 의미한다. pd.set_option('display.max_colwidth', -1) 참고 stackoverflow.com/questions/25351968/how-to-display-full-non-truncated-dataframe-information-in-html-when-convertin How to display full (non-truncated) dataframe information in html when converting from pandas dataframe to html? I converted a pa..

pandas dataframe에 row 추가하기

mem_no prd_no 0 100 1000 1 200 2000 위와 같은 df라는 이름의 DataFrame이 있을 때 한 행을 추가하고 싶을 수 있다. 이 때는 아래와 같이 진행하면 된다. import pandas as pd list1 = [300, 3000] df2 = df.append(pd.Series(list1, index=df.columns), ignore_index=True) df2 위와 같이 처리하면 한 행이 추가된 것을 확인할 수 있다. 참고 emilkwak.github.io/dataframe-list-row-append-ignore-index

spark에서 pandas 대신 databricks의 koalas 이용하기

pandas는 spark에서 분산 병렬 처리가 되지 않기 때문에 대용량 데이터를 다루기에는 한계가 있다. 그렇다고 spark의 dataframe을 이용하면 pandas에 비해서 기능이 부족하거나 불편한 경우가 있다. 이런 경우에는 databricks에서 만든 koalas를 이용하면 된다. koalas는 분산 병렬처리가 가능하고, 문법도 pandas와 유사해서 어려움 없이 이용할 수 있다. 아래는 koalas를 이용해 df의 describe() 함수를 이용하는 방법이다. import databricks.koalas as ks sdf = spark.sql("select cnt from table") # koalas df로 변환 kdf = sdf.to_koalas() kdf.describe() ##결과 cou..

pandas.DataFrame.iloc

DataFrame.iloc 정의 - 정수 값을 이용해 데이터프레임의 특정 위치를 인덱스 기반으로 선택한다. .iloc[]는 주로 0부터 축의 길이 -1 사이의 정수값으로 사용 가능 가능하지만, boolean array를 사용할 수도 있다. 아래와 같이 이용 가능하다 An integer, e.g. 5.A list or array of integers, e.g. [4, 3, 0].A slice object with ints, e.g. 1:7.A boolean array.A callable function with one argument (the calling Series, DataFrame or Panel) and that returns valid output for indexing (one of the a..

728x90