File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -690,7 +690,7 @@ def read_data(ticker_list,
690
690
ticker_df = pl.concat(all_data)
691
691
692
692
# Pivot to have tickers as columns
693
- ticker_df = ticker_df.pivot(values='Close', index='Date', columns ='ticker')
693
+ ticker_df = ticker_df.pivot(values='Close', index='Date', on ='ticker')
694
694
695
695
return ticker_df
696
696
@@ -721,12 +721,12 @@ First, you can extract the data and perform the calculation such as:
721
721
first_prices = ticker[0] # First row
722
722
last_prices = ticker[-1] # Last row
723
723
724
- # Convert to pandas for easier calculation
725
- first_pd = ticker.head(1).to_pandas().iloc[0]
726
- last_pd = ticker.tail(1).to_pandas().iloc[0]
724
+ # Convert to pandas for easier calculation, excluding Date column to avoid type errors
725
+ numeric_cols = [col for col in ticker.columns if col != 'Date']
726
+ first_pd = ticker.head(1).select(numeric_cols).to_pandas().iloc[0]
727
+ last_pd = ticker.tail(1).select(numeric_cols).to_pandas().iloc[0]
727
728
728
729
price_change = (last_pd - first_pd) / first_pd * 100
729
- price_change = price_change.dropna() # Remove Date column
730
730
price_change
731
731
```
732
732
You can’t perform that action at this time.
0 commit comments