Pandas가이 경고를 발행하면 정확히 어떻게됩니까? 걱정해야할까요?
In [1]: read_csv(path_to_my_file)
/Users/josh/anaconda/envs/py3k/lib/python3.3/site-packages/pandas/io/parsers.py:1139:
DtypeWarning: Columns (4,13,29,51,56,57,58,63,87,96) have mixed types. Specify dtype option on import or set low_memory=False.
data = self._reader.read(nrows)
이것은 Pandas가 해당 열의 값에서 유형을 추론 할 수 없음을 의미한다고 가정합니다. 그렇다면 Pandas는 이러한 열에 어떤 유형을 사용하게 될까요 ?
또한 유형은 사후에 항상 복구 할 수 있습니까? (경고를받은 후) 또는 원본 정보를 정확하게 복구 할 수없는 경우가 있으며, 유형을 미리 지정해야합니까?
마지막으로 low_memory = False
가 문제를 정확히 어떻게 해결합니까?
해결 방법
low_memory : 부울, 기본값 True
내부적으로 파일을 청크 단위로 처리하므로 메모리 사용량이 줄어 듭니다. parsing, but possibly mixed type inference. To ensure no mixed types either set False, or specify the type with the dtype parameter. Note that the entire file is read into a single DataFrame regardless, use the chunksize or iterator parameter to return the data 덩어리로. (C 파서에서만 유효 함)
그것은 결정적입니다-유형은 무엇을 기반으로 일관되게 추론됩니다. in the data. That said, the internal chunksize is not a fixed number of rows, but instead bytes, so whether you can a mixed dtype warning 또는 약간 무작위로 느낄 수 없습니다.
그렇다면 Pandas는 이러한 열에 어떤 유형을 사용하게 될까요?
이것은 다음과 같은 자체 포함 된 예에서 답합니다.
df=pd.read_csv(StringIO('\n'.join([str(x) for x in range(1000000)] + ['a string'])))
DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False.
type(df.loc[524287,'0'])
Out[50]: int
type(df.loc[524288,'0'])
Out[51]: str
csv 데이터의 첫 번째 부분은 int로만 표시되었으므로 int로 변환됩니다. 두 번째 부분에도 문자열이 있으므로 모든 항목이 문자열로 유지되었습니다.
사후에 항상 유형을 복구 할 수 있나요? (경고를받은 후)?
csv로 다시 내보내고 low_memory = False
로 다시 읽는 것이 작업을 수행해야한다고 생각합니다.
low_memory = False는 정확히 어떻게 문제를 해결하나요?
유형을 결정하기 전에 모든 파일을 읽으므로 더 많은 메모리가 필요합니다.
참조 페이지 https://stackoverflow.com/questions/25488675
'파이썬' 카테고리의 다른 글
파이썬 matplotlib의 imshow ()에 범례를 추가하는 방법 (0) | 2020.12.10 |
---|---|
파이썬 Python을 사용하여 MySQL 데이터베이스에 INSERT 한 후 "id"를 어떻게 얻습니까? (0) | 2020.12.10 |
파이썬 Python3 : 요청 라이브러리없이 JSON POST 요청 (0) | 2020.12.10 |
파이썬 조인을 사용하는 Pandas의 vlookup (0) | 2020.12.09 |
파이썬 ipython 노트북에 인쇄되지 않음 (0) | 2020.12.09 |
댓글