복붙노트

[PYTHON] 팬더가 인식하는 모든 유형은 무엇입니까?

PYTHON

팬더가 인식하는 모든 유형은 무엇입니까?

팬더의 경우, 다른 데이터 유형이 있다면

(i) float64, int64 (및 float32, int8 등의 np.number의 다른 변형)

(이) 수영장

(iii) datetime64, timedelta64

문자열 열과 같은, 항상 개체의 dtype가?

또는 위의 목록에서 (i), (ii) 및 (iii)과 다른 데이터 유형이있는 경우 pandas가 객체를 dtype으로 만들지 않는지 알고 싶습니다.

해결법

  1. ==============================

    1.uint8도 있습니다.

    uint8도 있습니다.

    dtypes에 대한 Pandas 문서에는 훨씬 더 많은 정보가 있습니다.

  2. ==============================

    2.pandas는 nump에서 dtype을 빌려옵니다. 이에 대한 데모는 다음을 참조하십시오.

    pandas는 nump에서 dtype을 빌려옵니다. 이에 대한 데모는 다음을 참조하십시오.

    import pandas as pd
    
    df = pd.DataFrame({'A': [1,'C',2.]})
    df['A'].dtype
    
    >>> dtype('O')
    
    type(df['A'].dtype)
    
    >>> numpy.dtype
    

    설명서에서 유효한 numpy.dtype 목록을 찾을 수 있습니다.

    팬더는 이러한 유형을 지원해야합니다. 위의 옵션 중 하나를 입력 인자로 사용하여 pandas.Series 객체의 astype 메소드를 사용하면 팬더가 해당 유형을 해당 유형으로 변환하려고합니다 (또는 적어도 객체 유형으로 다시 떨어지는 경우). 'u'만이 ​​팬더가 전혀 이해하지 못하는 것을 볼 수있는 유일한 사람입니다.

    df['A'].astype('u')
    
    >>> TypeError: data type "u" not understood
    

    이것은 'u'다음에 항목 당 바이트 수를 지정하는 숫자 (유효해야 함)가 필요하기 때문에 결과가 누락되는 오류입니다.

    import numpy as np
    
    np.dtype('u')
    
    >>> TypeError: data type "u" not understood
    
    np.dtype('u1')
    
    >>> dtype('uint8')
    
    np.dtype('u2')
    
    >>> dtype('uint16')
    
    np.dtype('u4')
    
    >>> dtype('uint32')
    
    np.dtype('u8')
    
    >>> dtype('uint64')
    
    # testing another invalid argument
    np.dtype('u3')
    
    >>> TypeError: data type "u3" not understood
    

    요약하면, 팬더 객체의 astype 메소드는 numpy.dtype에 유효한 인수를 사용하여 합리적인 방법으로 시도하고 수행합니다. numpy.dtype ( 'f')은 numpy.dtype ( 'float32')과 같으며 numpy.dtype ( 'f8')은 numpy.dtype ( 'float64') 등과 동일합니다. pandas astype 방법에 대한 논쟁.

    NumPy에서 각 데이터 유형 클래스를 찾으려면 팬더 문서에서 다음을 권장합니다.

    def subdtypes(dtype):
        subs = dtype.__subclasses__()
        if not subs:
            return dtype
        return [dtype, [subdtypes(dt) for dt in subs]]
    
    subdtypes(np.generic)
    

    산출:

    [numpy.generic,
     [[numpy.number,
       [[numpy.integer,
         [[numpy.signedinteger,
           [numpy.int8,
            numpy.int16,
            numpy.int32,
            numpy.int64,
            numpy.int64,
            numpy.timedelta64]],
          [numpy.unsignedinteger,
           [numpy.uint8,
            numpy.uint16,
            numpy.uint32,
            numpy.uint64,
            numpy.uint64]]]],
        [numpy.inexact,
         [[numpy.floating,
           [numpy.float16, numpy.float32, numpy.float64, numpy.float128]],
          [numpy.complexfloating,
           [numpy.complex64, numpy.complex128, numpy.complex256]]]]]],
      [numpy.flexible,
       [[numpy.character, [numpy.bytes_, numpy.str_]],
        [numpy.void, [numpy.record]]]],
      numpy.bool_,
      numpy.datetime64,
      numpy.object_]]
    

    팬더는 이러한 클래스를 유효한 유형으로 받아들입니다. 예를 들어, dtype = { 'A': np.float}.

    NumPy 문서에는 자세한 내용과 차트가 포함되어 있습니다.

  3. from https://stackoverflow.com/questions/29245848/what-are-all-the-dtypes-that-pandas-recognizes by cc-by-sa and MIT license