python里面df代表什么意思_python – df [x],df [[x]],df [‘x’],df [[‘x’]]和df.x之间的差异...

> df [x] – 使用变量x索引列.返回pd.Series

> df [[x]] – 使用变量x索引/切片单列DataFrame.返回pd.DataFrame

> df [‘x’] – 索引名为“x”的列.返回pd.Series

> df [[‘x’]] – 索引/切片只有一列名为“x”的单列DataFrame.返回pd.DataFrame

> df.x – 点访问符号,相当于df [‘x’](但是,如果要成功使用点符号,则可以命名为

limitations.)返回pd.Series

使用单括号[…],您只能将单列索引为系列.使用双括号[[…]],您可以根据需要选择任意数量的列,这些列将作为新DataFrame的一部分返回.

建立

df

ID x

0 0 0

1 1 15

2 2 0

3 3 0

4 4 0

5 5 15

x = 'ID'

例子

df[x]

0 0

1 1

2 2

3 3

4 4

5 5

Name: ID, dtype: int64

type(df[x])

pandas.core.series.Series

df['x']

0 0

1 15

2 0

3 0

4 0

5 15

Name: x, dtype: int64

type(df['x'])

pandas.core.series.Series

df[[x]]

ID

0 0

1 1

2


版权声明:本文为weixin_29416253原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。