pandas df"A"和"B 1"是列名.如何像df.A一样引用"B 1"? [英] Pandas df 'A' and 'B 1' are column name. How do I reference 'B 1' like df.A ?

查看:50
本文介绍了 pandas df"A"和"B 1"是列名.如何像df.A一样引用"B 1"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于列名(例如"C.1")也存在同样的问题... 除了df['B 1']df['C.1']之外,列名'B 1'和'C 1'是否有类似于df.A的捷径?

The same question holds for column names such as 'C.1'... Is there a short cut like df.A for column names 'B 1' and 'C 1' other than df['B 1'] and df['C.1'] ?

推荐答案

如果列名不能使用点表示法来访问列

You cannot use the dot notation to access columns if the column name

  • 以数字开头
  • 包含空格字符
  • 包含运算符和标点符号
  • 与现有方法名称或属性冲突

点表示法类似于访问对象的属性,如果要以这种方式访问​​它们,则必须遵循python的变量命名规则.除此之外,您还必须使用[...].

The dot notation is similar to accessing object's attributes, and you must follow python's variable naming rules if you want to access them that way. For anything else, you'll have to use [...].

有关详细信息,请查看

For a more detailed view, view the note at the bottom of the documentation.

这篇关于 pandas df"A"和"B 1"是列名.如何像df.A一样引用"B 1"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆