• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

괄호 사용

22.08.01 13:45 작성 조회수 155

1

괄호 사용이 헷갈려 질문드립니다.
 
어떤경우에는 괄호 사용하면 오류메시지가 뜨고
어떤 경우에는 과호가 없으면 오류메시지가 뜨고
ex) df.shape / df.head()
 
이렇듯 괄호사용의 기준에 대해서 알려주시면 감사하겠습니다.
 

답변 1

답변을 작성해보세요.

1

안녕하세요.

판다스 내부에 구현된 기능들은 Attributes 와 Method 가 있습니다.

괄호가 없는 것은 Attributes 이고 괄호가 있는 것은 Method 로 구현이 되어 있어요.

이건 오픈소스 개발자들이 굳이 옵션이 없이 값을 보고자 하는 것들은 Attributes 로 개발을 해두었고, 하지만 Attributes 중에도 괄호가 들어가는 것들이 있습니다.

head(), tail() 처럼 갯수를 지정한다든지 sort_values()에서 조건을 지정한다든지 조건이 필요한 것들은 Method로 구현을 해두었습니다.

 

그래서 아쉽게도 이 부분은 문서를 참고해서 사용하는 것을 추천합니다. 공식문서의 링크를 참고해 보세요!

[Series — pandas 1.4.3 documentation](https://pandas.pydata.org/docs/reference/series.html)

[DataFrame — pandas 1.4.3 documentation](https://pandas.pydata.org/docs/reference/frame.html)

 

다음은 시리즈의 Attributes 입니다.

Attributes

Axes

Series.index

The index (axis labels) of the Series.

Series.array

The ExtensionArray of the data backing this Series or Index.

Series.values

Return Series as ndarray or ndarray-like depending on the dtype.

Series.dtype

Return the dtype object of the underlying data.

Series.shape

Return a tuple of the shape of the underlying data.

Series.nbytes

Return the number of bytes in the underlying data.

Series.ndim

Number of dimensions of the underlying data, by definition 1.

Series.size

Return the number of elements in the underlying data.

Series.T

Return the transpose, which is by definition self.

Series.memory_usage([index, deep])

Return the memory usage of the Series.

Series.hasnans

Return True if there are any NaNs.

Series.empty

Indicator whether Series/DataFrame is empty.

Series.dtypes

Return the dtype object of the underlying data.

Series.name

Return the name of the Series.

Series.flags

Get the properties associated with this pandas object.

Series.set_flags(*[, copy, ...])

Return a new object with updated flags.

 

다음은 데이터프레임의 Attributes 입니다. 하지만 Attributes 중에도 괄호가 있는 것도 있으니 문서를 참고해 주세요!

Attributes and underlying data

Axes

DataFrame.index

The index (row labels) of the DataFrame.

DataFrame.columns

The column labels of the DataFrame.

DataFrame.dtypes

Return the dtypes in the DataFrame.

DataFrame.info([verbose, buf, max_cols, ...])

Print a concise summary of a DataFrame.

DataFrame.select_dtypes([include, exclude])

Return a subset of the DataFrame's columns based on the column dtypes.

DataFrame.values

Return a Numpy representation of the DataFrame.

DataFrame.axes

Return a list representing the axes of the DataFrame.

DataFrame.ndim

Return an int representing the number of axes / array dimensions.

DataFrame.size

Return an int representing the number of elements in this object.

DataFrame.shape

Return a tuple representing the dimensionality of the DataFrame.

DataFrame.memory_usage([index, deep])

Return the memory usage of each column in bytes.

DataFrame.empty

Indicator whether Series/DataFrame is empty.

DataFrame.set_flags(*[, copy, ...])

Return a new object with updated flags.