Pandas DataFrame列命名约定 [英] Pandas DataFrame column naming conventions

查看:64
本文介绍了Pandas DataFrame列命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何常用的Pandas DataFrame列命名约定?是否在这里推荐 PEP8 (例如实例变量)?

Is there any commonly used Pandas DataFrame column naming convention? Is PEP8 recommended here (ex. instance variables)?

意识到很多数据是从带有标头的外部源加载的,但是我很好奇当我必须自己命名/重命名列时正确的方法是什么吗?

Concious that lots of data is loaded from external sources with headers but I'm curious what is the correct approach when I have to name/rename the columns on my own?

推荐答案

某些人倾向于使用 snake_case (带下划线的小写字母),这样他们就可以使用像df.my_column

Some people tend to use snake_case (lower case with underscores) so that they can access the column using period like this df.my_column

我倾向于总是使用df['my_column']语法访问列,因为它避免了与DataFrame方法和属性的混淆,并且更容易扩展到切片和奇特的索引编制,因此不需要使用蛇形情况.

I tend to always access colums using the df['my_column'] syntax because it avoids confusion with DataFrame methods and properties, and it easier to extend to slices and fancy indexing, so the snake case is not necessary.

简而言之,我认为您应该使用对潜在读者最清楚的内容.

In short, I think you should use whatever is clearest to a potential reader.

这篇关于Pandas DataFrame列命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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