File tree Expand file tree Collapse file tree
docs/notes/financial-data-sources Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,15 +62,32 @@ df = tickers.history()
6262df.head()
6363```
6464
65+ ``` {python}
66+ df.tail()
67+ ```
68+
6569Simplifying the multi-index:
6670
6771``` {python}
68- from pandas import to_datetime
69-
7072df["symbol"] = df.index.get_level_values(0)
71- df["date"] = to_datetime( df.index.get_level_values(1)).date
73+ df["date"] = df.index.get_level_values(1)
7274
7375df.reset_index(drop=True, inplace=True)
76+
77+ df[["date", "symbol", "adjclose"]].head()
78+ ```
79+
80+ Optionally converting dates to be datetime-aware:
81+
82+ ``` {python}
83+ from pandas import to_datetime
84+
85+ # fix date values (see: https://github.com/dpguthrie/yahooquery/issues/210)
86+ df["date"] = df["date"].astype("str")
87+ df["date"] = df["date"].str.split(" ").str[0]
88+ # convert to datetime-aware values:
89+ df["date"] = to_datetime(df["date"]).dt.date
90+
7491df[["date", "symbol", "adjclose"]].head()
7592```
7693
You can’t perform that action at this time.
0 commit comments