인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

이민형님의 프로필 이미지
이민형

작성한 질문수

공공데이터로 파이썬 데이터 분석 시작하기

소스코드와 데이터 다운로드 위치

.뒤에 명령을 실행할 때 () 유무 차이

작성

·

202

1

df_last 같은 변수 뒤에 .을 붙이고 copy() 같은 명령을 실행할 때 ()를 붙이는 기준이 따로 있나요?

copy같은 경우는 ()를 붙일때와 안 붙일때 나오는 값의 형태가 다른 거 같은데 어떤 차이가 있는 건가요?

답변 1

1

박조은님의 프로필 이미지
박조은
지식공유자

안녕하세요.

좋은질문을 해주셨네요. 

소괄호가 붙고 안 붙고의 차이는 Attributes 와 Methods 의 차이입니다.

아래 판다스 DataFrame의 Attributes 와 Methods 목록을 가져왔는데요.

가장 큰 차이는 옵션이 있는지 없는지에 대한 차이가 될거 같아요.

예를 들어 shape는 반환값이 (행, 열) 튜플로 반환이 되는데 이건 옵션이 따로 있지 않아요.

head()는 메소드인데 n 값에 대한 옵션이 있어요.

아래는 DataFrame 의 API 목록인데 Series 를 사용하더라도 같은 방법으로 대부분 사용하실 수 있습니다.

아래 링크를 참고해 보세요.

[pandas.DataFrame — pandas 1.0.3 documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html)

Attributes

T

Transpose index and columns.

at

Access a single value for a row/column label pair.

attrs

Dictionary of global attributes on this object.

axes

Return a list representing the axes of the DataFrame.

columns

The column labels of the DataFrame.

dtypes

Return the dtypes in the DataFrame.

empty

Indicator whether DataFrame is empty.

iat

Access a single value for a row/column pair by integer position.

iloc

Purely integer-location based indexing for selection by position.

index

The index (row labels) of the DataFrame.

loc

Access a group of rows and columns by label(s) or a boolean array.

ndim

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

shape

Return a tuple representing the dimensionality of the DataFrame.

size

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

style

Returns a Styler object.

values

Return a Numpy representation of the DataFrame.

Methods

abs(self)

Return a Series/DataFrame with absolute numeric value of each element.

add(self, other[, axis, level, fill_value])

Get Addition of dataframe and other, element-wise (binary operator add).

add_prefix(self, prefix)

Prefix labels with string prefix.

add_suffix(self, suffix)

Suffix labels with string suffix.

agg(self, func[, axis])

Aggregate using one or more operations over the specified axis.

aggregate(self, func[, axis])

Aggregate using one or more operations over the specified axis.

align(self, other[, join, axis, level, …])

Align two objects on their axes with the specified join method.

all(self[, axis, bool_only, skipna, level])

Return whether all elements are True, potentially over an axis.

any(self[, axis, bool_only, skipna, level])

Return whether any element is True, potentially over an axis.

append(self, other[, ignore_index, …])

Append rows of other to the end of caller, returning a new object.

apply(self, func[, axis, raw, result_type, args])

Apply a function along an axis of the DataFrame.

applymap(self, func)

Apply a function to a Dataframe elementwise.

asfreq(self, freq[, method, fill_value])

Convert TimeSeries to specified frequency.

asof(self, where[, subset])

Return the last row(s) without any NaNs before where.

assign(self, \*\*kwargs)

Assign new columns to a DataFrame.

astype(self, dtype, copy, errors)

Cast a pandas object to a specified dtype dtype.

at_time(self, time, asof[, axis])

Select values at particular time of day (e.g.

between_time(self, start_time, end_time, …)

Select values between particular times of the day (e.g., 9:00-9:30 AM).

bfill(self[, axis, limit, downcast])

Synonym for DataFrame.fillna() with method='bfill'.

bool(self)

Return the bool of a single element PandasObject.

boxplot(self[, column, by, ax, fontsize, …])

Make a box plot from DataFrame columns.

clip(self[, lower, upper, axis])

Trim values at input threshold(s).

combine(self, other, func[, fill_value, …])

Perform column-wise combine with another DataFrame.

combine_first(self, other)

Update null elements with value in the same location in other.

convert_dtypes(self, infer_objects, …)

Convert columns to best possible dtypes using dtypes supporting pd.NA.

copy(self, deep)

Make a copy of this object’s indices and data.

corr(self[, method, min_periods])

Compute pairwise correlation of columns, excluding NA/null values.

corrwith(self, other[, axis, drop, method])

Compute pairwise correlation.

count(self[, axis, level, numeric_only])

Count non-NA cells for each column or row.

cov(self[, min_periods])

Compute pairwise covariance of columns, excluding NA/null values.

cummax(self[, axis, skipna])

Return cumulative maximum over a DataFrame or Series axis.

cummin(self[, axis, skipna])

Return cumulative minimum over a DataFrame or Series axis.

cumprod(self[, axis, skipna])

Return cumulative product over a DataFrame or Series axis.

cumsum(self[, axis, skipna])

Return cumulative sum over a DataFrame or Series axis.

describe(self[, percentiles, include, exclude])

Generate descriptive statistics.

diff(self[, periods, axis])

First discrete difference of element.

div(self, other[, axis, level, fill_value])

Get Floating division of dataframe and other, element-wise (binary operator truediv).

divide(self, other[, axis, level, fill_value])

Get Floating division of dataframe and other, element-wise (binary operator truediv).

dot(self, other)

Compute the matrix multiplication between the DataFrame and other.

drop(self[, labels, axis, index, columns, …])

Drop specified labels from rows or columns.

drop_duplicates(self, subset, …)

Return DataFrame with duplicate rows removed.

droplevel(self, level[, axis])

Return DataFrame with requested index / column level(s) removed.

dropna(self[, axis, how, thresh, subset, …])

Remove missing values.

duplicated(self, subset, Sequence[Hashable], …)

Return boolean Series denoting duplicate rows.

eq(self, other[, axis, level])

Get Equal to of dataframe and other, element-wise (binary operator eq).

equals(self, other)

Test whether two objects contain the same elements.

eval(self, expr[, inplace])

Evaluate a string describing operations on DataFrame columns.

ewm(self[, com, span, halflife, alpha, …])

Provide exponential weighted functions.

이민형님의 프로필 이미지
이민형

작성한 질문수

질문하기