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,
690690 ticker_df = pl.concat(all_data)
691691
692692 # 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')
694694
695695 return ticker_df
696696
@@ -721,12 +721,12 @@ First, you can extract the data and perform the calculation such as:
721721first_prices = ticker[0] # First row
722722last_prices = ticker[-1] # Last row
723723
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]
727728
728729price_change = (last_pd - first_pd) / first_pd * 100
729- price_change = price_change.dropna() # Remove Date column
730730price_change
731731```
732732
You can’t perform that action at this time.
0 commit comments