How do I reset the returned DataFrame? #1818
Replies: 3 comments 1 reply
-
Can you photoshop what you want the structure to be? |
Beta Was this translation helpful? Give feedback.
-
This is how I want it. I managed to create the format I wanted but the way I did it is very ugly and I am not proud of it hehe. Typically when using pandas you want to start with a simple dataframe with numerically indexed rows, and all identifiers and useful data as simple column values. You can then assign indexes like Date, Ticker which can be used to reference certain portions of the data more easily, speed up execution, etc. The DataFrame I linked in the OP is far from simple, or panda-esque. It has an index which is Date, but also has a nested column reference structure which is very difficult to use in groupby's, joins, and other data wrangling operations. And at least to my experience, it's very difficult to get rid of. It would be much better if we returned a pandas DataFrame with a MultiIndex from the download/history methods. Then we could just call reset_index, pivot, and melt, to reformat the dataframe however we want. |
Beta Was this translation helpful? Give feedback.
-
It's a In any case, I have long wanted to propose creating a set of "official" functions that will return raw JSON instead of pandas DataFrame. |
Beta Was this translation helpful? Give feedback.
-
Hello, I've spent way too much time on this and figured I should ask here instead of banging my head against a wall.
How is the DataFrame that is returned by yahoo:_finance.download(... created?
I want a simple unindexed DataFrame with all of the columns you see there, except that the ticker index becomes a column with a string value describing which ticker it is instead of an index.
If I do reset_index, the Date column is reset and made into a regular column. If I then try to reference or reset the index again, the Ticker index is not affected at all. If I print the index of the new DataFrame, it seems to think there is no index at all (except a range) but obviously the indexes are not gone since the DataFrame still looks like this;
How do I actually reset the DataFrame? I don't want any indexes at all. Just regular ol' columns.
Edit; Just to be superclear, I just want to remove the "indexes" which are the Ticker names, like MSFT and META and turn them into a regular column, like "Ticker": ["Meta", "MSFT"].. but I have no idea what this structure actually is. It doesn't seem to be an index but is referenced similar to an index?
Beta Was this translation helpful? Give feedback.
All reactions