DBILITY

독거 가능성 100% 노후에 라면값이라도 하게 센스를 발휘합시다!😅
Please click on the ad so that I can pay for ramen in my old age!
点击一下广告,让老后吃个泡面钱吧!
老後にラーメン代だけでもするように広告を一回クリックしてください。

python pandas dataframe 본문

python

python pandas dataframe

DBILITY 2021. 10. 12. 21:12
반응형

R의 dataframe을 사용해 봤는데, 기억이 나질 않는다.^^;

공식문서를 참조하자. https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html

 

pandas.DataFrame — pandas 1.3.3 documentation

Column labels to use for resulting frame when data does not have them, defaulting to RangeIndex(0, 1, 2, …, n). If data contains column labels, will perform column selection instead.

pandas.pydata.org

2차원의 변경 가능하고 칼럼 별로 다른 데이터 타입의 저장이 가능하다.

기본구조는 다음과 같다.
pandas.DataFrame(data=Noneindex=Nonecolumns=Nonedtype=Nonecopy=None)

  1. Dictionary로 생성
    >>> import pandas as pd
    >>> dct = {'col1': [1, 2], 'col2': ['a', 'b']}
    >>> dct
    {'col1': [1, 2], 'col2': ['a', 'b']}
    >>> type(dct)
    <class 'dict'>
    >>> df = pd.DataFrame(data=dct)
    >>> df
       col1 col2
    0     1    a
    1     2    b
    >>> df.dtypes
    col1     int64
    col2    object
    dtype: object
  2. Numpy ndarray로 생성
    >>> ndarr = np.array([[1,2,3],[4,5,6],[7,8,9]])
    >>> type(ndarr)
    <class 'numpy.ndarray'>
    >>> df2 = pd.DataFrame(data=ndarr,columns=['a','b','c'])
    >>> df2
       a  b  c
    0  1  2  3
    1  4  5  6
    2  7  8  9
    >>> type(df2)
    >>> <class 'pandas.core.frame.DataFrame'>
    df2.dtypes
    a    int32
    b    int32
    c    int32
    dtype: object​

나머지는 필요할 때 공식문서를 참고하자.

반응형
Comments