반응형
반응형

pandas documentation - python

 

https://pandas.pydata.org/docs/index.html

 

pandas documentation — pandas 1.4.1 documentation

The reference guide contains a detailed description of the pandas API. The reference describes how the methods work and which parameters can be used. It assumes that you have an understanding of the key concepts.

pandas.pydata.org

 

반응형
반응형

[Python] In dictionary, converting the value from string to integer. 

Dict에서 value가 숫자형이 아닐때 숫자로 변경

Taking this below example :

'user_stats': {'Blog': '1',
                'Discussions': '2',
                'Followers': '21',
                'Following': '21',
                'Reading': '5'},

I want to convert it into:

'Blog' : 1 , 'Discussion': 2, 'Followers': 21, 'Following': 21, 'Reading': 5

 

>>> d = {'Blog': '1', 'Discussions': '2', 'Followers': '21', 'Following': '21', 'Reading': '5'}
>>> dict((k, int(v)) for k, v in d.iteritems())
{'Blog': 1, 'Discussions': 2, 'Followers': 21, 'Following': 21, 'Reading': 5}

 

https://stackoverflow.com/questions/9224385/in-dictionary-converting-the-value-from-string-to-integer

 

In dictionary, converting the value from string to integer

Taking this below example : 'user_stats': {'Blog': '1', 'Discussions': '2', 'Followers': '21', 'Following': '21', 'Reading': '5'}, ...

stackoverflow.com

 

반응형
반응형

[python] pandas.DataFrame.to_csv  

쉼표로 구분된 값(csv) 파일에 DataFrame 쓰기

 

 

매개변수: 

path_or_buf : 문자열 또는 파일 핸들, 기본값 없음
파일 경로 또는 개체(None이 제공된 경우) 결과는 문자열로 반환됩니다.

sep : 문자, 기본값 ","
출력 파일의 필드 구분 기호입니다.

na_rep : 문자열, 기본값 ''
누락된 데이터 표현

float_format : 문자열, 기본값 없음
부동 소수점 숫자의 형식 문자열

열 : 시퀀스, 선택 사항
쓸 열

header : 부울 또는 문자열 목록, 기본값은 True
열 이름을 작성합니다. 문자열 목록이 제공되면 열 이름의 별칭으로 간주됩니다.

인덱스 : 부울, 기본값 True
행 이름 쓰기(색인)

index_label : 문자열 또는 시퀀스, 또는 False, 기본값 없음
원하는 경우 인덱스 열의 열 레이블입니다. None이 주어지고 헤더 와 인덱스 가 True이면 인덱스 이름이 사용됩니다. DataFrame이 MultiIndex를 사용하는 경우 시퀀스를 지정해야 합니다. False이면 인덱스 이름에 대한 필드를 인쇄하지 않습니다. R에서 더 쉽게 가져오려면 index_label=False를 사용하세요.

nanRep : 없음
더 이상 사용되지 않음, na_rep 사용

mode : str
Python 쓰기 모드, 기본값 'w'

encoding : 문자열, 선택 사항
내용이 ASCII가 아닌 경우 사용할 인코딩을 나타내는 문자열(3 이전의 python 버전용)

line_terminator : 문자열, 기본값 '\n'
출력 파일에 사용할 개행 문자 또는 문자 시퀀스  - new line 제거하려면 line_terminator=False

quotechar : csv 모듈의 선택적 상수
기본값은 csv.QUOTE_MINIMAL입니다.

quotechar : 문자열(길이 1), 기본값 '"'
필드를 인용하는 데 사용되는 문자

doublequote : 부울, 기본값 True
필드 내에서 인용 부호 제어

escapechar : 문자열(길이 1), 기본값 없음
적절한 경우 sep 및 quotechar 를 이스케이프하는 데 사용되는 문자

chunksize  : int 또는 없음

한 번에 쓸 행

tupleize_cols : 부울, 기본값은 False

multi_index 열을 튜플 목록으로 작성(True인 경우) 또는 False인 경우 새(확장된 형식)

date_format : 문자열, 기본값 없음
날짜/시간 객체의 형식 문자열

cols : 열의 kwarg 전용 별칭 [더 이상 사용되지 않음]

반응형
반응형

Pandas .Series 의 item , to_CSV

pandas.Series.items

 

 

s = pd.Series(['A', 'B', 'C'])
>>> for index, value in s.items():
...     print(f"Index : {index}, Value : {value}")
Index : 0, Value : A
Index : 1, Value : B
Index : 2, Value : C

https://github.com/pandas-dev/pandas/blob/v1.4.1/pandas/core/series.py#L1662-L1689

 

GitHub - pandas-dev/pandas: Flexible and powerful data analysis / manipulation library for Python, providing labeled data struct

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more - GitHub - pandas-dev/...

github.com

 

 

 

 

반응형
반응형

Pandas df.to_csv("file.csv" encode="utf-8") still gives trash characters for minus sign

 

Pandas df.to_csv("file.csv" encode="utf-8") still gives trash characters for minus sign

I've read something about a Python 2 limitation with respect to Pandas' to_csv( ... etc ...). Have I hit it? I'm on Python 2.7.3 This turns out trash characters for ≥ and - when they appear in st...

stackoverflow.com

https://stackoverflow.com/questions/25788037/pandas-df-to-csvfile-csv-encode-utf-8-still-gives-trash-characters-for-min
pandas dataframe을 csv 형태로,  to_csv 


utf-8 encoding으로 저장하면 
내용 중 한글이 깨지는 문제 발생
euc-kr 로 저장할 때는 문제 없음
df.to_csv('file.csv',encoding='euc-kr')


df.to_csv('file.csv',encoding='utf-8')
한글 깨짐


해결책: df.to_csv('file.csv',encoding='utf-8-sig')


windows 환경 (정확히는 win7)
Python 3.6.4 :: Anaconda custom (64-bit)
pandas==0.23.4

 

 

 

 

 

 

 

반응형
반응형

KoNLPy 한국어 처리 패키지

OSS project 한나눔(Hannanum)
한국어 형태소 분석시 + 음차표기

 

 

http://semanticweb.kaist.ac.kr/hannanum/

 

Semantic Web Research Center(Hannanum)

3. 세부 개발 목표 O 기능 개선 - 형태소 분석기의 핵심 기능 중 음운 규칙, 품사 관리 및 사전 관리의 모듈화 - 응용에 맞게 사용할 수 있는 음운 규칙, 품사, 사전을 각각 2가지 이상 제공 예정 -

semanticweb.kaist.ac.kr

 

https://datascienceschool.net/03%20machine%20learning/03.01.02%20KoNLPy%20%ED%95%9C%EA%B5%AD%EC%96%B4%20%EC%B2%98%EB%A6%AC%20%ED%8C%A8%ED%82%A4%EC%A7%80.html

 

KoNLPy 한국어 처리 패키지 — 데이터 사이언스 스쿨

.ipynb .pdf to have style consistency -->

datascienceschool.net

 

형태소 분석

KoNLPy는 다음과 같은 다양한 형태소 분석, 태깅 라이브러리를 파이썬에서 쉽게 사용할 수 있도록 모아놓았다.

반응형

+ Recent posts