-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More convenient syntax for DataFrame constructor to declare order of columns? #444
Comments
Maybe data = list of pandas.Series. Order is set inherently and column names or index values (depending on orient) can be extracted from the series (or set to default values when not available) lines up with;
I am not a big fan off one does it all |
Sure, @lodagro; alternate factory functions/consturctors would be just fine, and are indeed a cleaner alternative to making over-complicated |
I think it makes sense to have a constructor that takes the form that Fernando describes, since it's sort of a "dict-like" interface to begin with. At the moment the constructor will accept
maybe the method should be called like
to be analogous with dict.(iter)items and friends-- sounds good? And adding an |
Incidentally I half wish that I hadn't called the |
Sorry, what would |
Suppose that you intend for the keys to be the row labels instead of the column labels-- but you also want to infer the right dtype for the columns. If you did
to achieve that, but the values are, say, lists with mixed types-- the resulting DataFrame would currently come out as all dtype=object. |
analogous functionality is available in |
Ah, I get it now. Yes, then it sounds like such an alternate constructor, with the orient keyword, would be very useful and would simplify some calls. If you do implement it, you might want to make note of its existence in the docstring for |
OK, I wrote a DataFrame.from_items that I think does the right thing-- added some notes to the DataFrame docstring about other constructors, too |
Thanks @wesm! |
I've searched the list, docs and issue list and didn't find this addressed, sorry if it was. It seems to me that right now, if I want to specify the order of my columns in new DataFrame built from existing Series, the only way to do it is to build a dict and pass the columns argument separately, with a redundant spelling of the column names:
I'm wondering if a more convenient syntax could be devised for this operation. It seems that list-of-tuples already has different semantics, so the minimal change of the above doesn't work:
It's unfortunate, b/c the above is incidentally a valid dict constructor:
But since a list is an inherently ordered data structure, it would be nice if it was accepted also as a constructor for DataFrame, carrying with it the implicit column order.
The text was updated successfully, but these errors were encountered: