在下面的代码中,我将一个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