Skip to content

Commit 882d486

Browse files
committed
Overcome bug in yahooquery
1 parent b40e7bd commit 882d486

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

docs/notes/financial-data-sources/yahooquery.qmd

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,32 @@ df = tickers.history()
6262
df.head()
6363
```
6464

65+
```{python}
66+
df.tail()
67+
```
68+
6569
Simplifying the multi-index:
6670

6771
```{python}
68-
from pandas import to_datetime
69-
7072
df["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
7375
df.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+
7491
df[["date", "symbol", "adjclose"]].head()
7592
```
7693

0 commit comments

Comments
 (0)