ENH: df.columns returns list of series
Feature Type
-
[X] Adding new functionality to pandas
-
[X] Changing existing functionality in pandas
-
[ ] Removing existing functionality in pandas
Problem Description
Currently you can go df[{column label}] to access a column or df.columns to access the column labels. I propose either a new list that is like df.columns but with the series returned by df[{column}] or just replace df.columns with this new column. As long as you can access the label I don't see why not. This could also allow for adding or removinf new columns by editing df.columns
Feature Description
Completely new code could be needed or accessing the same as getitem does:
[i for i in indexes] with indexes being the columns.
Alternative Solutions
for i in df: column=df[i]
Additional Context
No response
Thanks for the request. I would recommend using [e for _, e in df.items()].
What advantage does adding a method here provide a user that is difficult / not possible today?
This could also allow for adding or removinf new columns by editing df.columns
Adding a new method for getting a list of Series wouldn't be that difficult (though im -1 since there are easy alternatives), but making it editable like this would be difficult.
I think the biggest problem is how DataFrame.values ended up being implemented. I'm slightly curious to know why it wasn't done to return an iterable of Series that follow the .keys and .items analog from dict
I would hazard a guess that .values as added prior to any active core member. In any case, I think it would be far too disruptive to change now.
Absolutely, I wasn't suggesting that. More being sympathetic to OP here.
closing, -1 on doing this as well