在下面的代碼中,我將一個csv文件導入到Python的熊貓庫中,並顯示前5行,並查詢熊貓數據框的'形狀'。爲什麼`head`需要`()`和`shape`不需要?
import pandas as pd
data = pd.read_csv('my_file.csv')
data.head() #returns the first 5 rows of the dataframe
data.shape # displays the # of rows and # of columns of dataframe
爲什麼是認爲
head()
方法需要空括號head
之後,但shape
不?它與它們的類型有關嗎? 如果我打電話給head
而沒有使用空括號跟着它,我不會得到相同的結果。head
是一種方法,shape
只是一個屬性?我怎樣才能將上述問題的答案概括爲Python的其餘部分?我想學習的不只是熊貓,而是一般的Python。例如,一個句子,如「當_____情況下,一個必須包括空括號是否將提供任何參數,但對於其他屬性一個不就得了?
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.head.html – Wen
*這是'head'是一種方法,'shape'只是一個屬性?* * *是。** – zondo
@zondo。謝謝。 「屬性」和「屬性」之間有什麼區別? – Semihcan