Im new in Pandas, and while playing with its Dataframe, i found method keys() which works pretty like dict.keys(). But I cannot find it in docs. What am i missing?
Im new in Pandas, and while playing with its Dataframe , i found method
Share
You can see where this is defined in the source:
And, if you look at the git blame, you can see it was added as a fix for #1240: “Request: keys() method on dataFrame”. The rationale seems to be:
However, it’s worth noting that
DataFramesupports only about half of the mapping interface. For example, there’siteritemsandkeys, but noiterkeys. And there are also cases where they added similar but not-quite-the-same names, likeiterkv, which is equivalent toiteritemsbut there specifically because the latter “gets incorrectly converted to .items() by 2to3”.You can go through the source and see where each of these were added and why, but there doesn’t seem to be too much rhyme or reason beyond “
DataFrameis kind of like adict, and kind of not.”The fact that they chose not to document most of these methods, or to document that
DataFrameis kind of like adict, I wouldn’t rely on any of this. Just usecolumnsinstead ofkeys(), etc.