Pandas df 'A' and 'B 1' are column name. How do I reference 'B 1' like df.A ?

前端 未结 1 1923
死守一世寂寞
死守一世寂寞 2021-01-24 19:55

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\']

相关标签:
1条回答
  • 2021-01-24 20:24

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

    • begins with a digit
    • contains whitespace characters
    • contains operator symbols and punctuation
    • conflicts with an existing method name or attribute

    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.

    0 讨论(0)
提交回复
热议问题