Comments (1)
prices['rsi'] = prices.groupby(level='symbol').close.apply(RSI)
ValueError Traceback (most recent call last) File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\frame.py:11610, in _reindex_for_setitem(value, index) 11609 try:
11610 reindexed_value = value.reindex(index)._values
11611 except ValueError as err:
11612 # raised in MultiIndex.from_tuples, see test_insert_error_msmgsFile ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\series.py:4918, in Series.reindex(self, index, axis, method, copy, level, fill_value, limit, tolerance) 4901 @doc( 4902 NDFrame.reindex, # type: ignore[has-type] 4903 klass=_shared_doc_kwargs["klass"], (...) 4916 tolerance=None, 4917 ) -> Series: -> 4918 return super().reindex( 4919 index=index, 4920 method=method, 4921 copy=copy, 4922 level=level, 4923 fill_value=fill_value, 4924 limit=limit, 4925 tolerance=tolerance, 4926 )
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\generic.py:5360, in NDFrame.reindex(self, labels, index, columns, axis, method, copy, level, fill_value, limit, tolerance) 5359 # perform the reindex on the axes -> 5360 return self._reindex_axes( 5361 axes, level, limit, tolerance, method, fill_value, copy 5362 ).finalize(self, method="reindex")
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\generic.py:5375, in NDFrame._reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy) 5374 ax = self._get_axis(a) -> 5375 new_index, indexer = ax.reindex( 5376 labels, level=level, limit=limit, tolerance=tolerance, method=method 5377 ) 5379 axis = self._get_axis_number(a)
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\indexes\base.py:4268, in Index.reindex(self, target, method, level, limit, tolerance) 4267 if self._index_as_unique: -> 4268 indexer = self.get_indexer( 4269 target, method=method, limit=limit, tolerance=tolerance 4270 ) 4271 elif self._is_multi:
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\indexes\base.py:3802, in Index.get_indexer(self, target, method, limit, tolerance) 3798 return this._get_indexer( 3799 target, method=method, limit=limit, tolerance=tolerance 3800 ) -> 3802 return self._get_indexer(target, method, limit, tolerance)
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\indexes\base.py:3823, in Index._get_indexer(self, target, method, limit, tolerance) 3821 # error: Item "IndexEngine" of "Union[IndexEngine, ExtensionEngine]" 3822 # has no attribute "_extract_level_codes" -> 3823 tgt_values = engine._extract_level_codes( # type: ignore[union-attr] 3824 target 3825 ) 3826 else:
File ~\anaconda3\envs\baclass\lib\site-packages\pandas_libs\index.pyx:714, in pandas._libs.index.BaseMultiIndexCodesEngine._extract_level_codes()
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\indexes\multi.py:143, in MultiIndexUIntEngine._codes_to_ints(self, codes) 141 # Shift the representation of each level by the pre-calculated number 142 # of bits: --> 143 codes <<= self.offsets 145 # Now sum and OR are in fact interchangeable. This is a simple 146 # composition of the (disjunct) significant bits of each level (i.e. 147 # each column in "codes") in a single positive integer:
ValueError: operands could not be broadcast together with shapes (2004775,2) (3,) (2004775,2)
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last) Cell In[44], line 1 ----> 1 prices['rsi'] = prices.groupby(level='symbol').close.apply(RSI)
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\frame.py:3950, in DataFrame.setitem(self, key, value) 3947 self._setitem_array([key], value) 3948 else: 3949 # set column -> 3950 self._set_item(key, value)
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\frame.py:4143, in DataFrame._set_item(self, key, value) 4133 def _set_item(self, key, value) -> None: 4134 """ 4135 Add series to DataFrame in specified column. 4136 (...) 4141 ensure homogeneity. 4142 """ -> 4143 value = self._sanitize_column(value) 4145 if ( 4146 key in self.columns 4147 and value.ndim == 1 4148 and not is_extension_array_dtype(value) 4149 ): 4150 # broadcast across multiple columns if necessary 4151 if not self.columns.is_unique or isinstance(self.columns, MultiIndex):
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\frame.py:4867, in DataFrame._sanitize_column(self, value) 4865 return _reindex_for_setitem(value, self.index) 4866 elif is_dict_like(value): -> 4867 return _reindex_for_setitem(Series(value), self.index) 4869 if is_list_like(value): 4870 com.require_length_match(value, self.index)
File ~\anaconda3\envs\baclass\lib\site-packages\pandas\core\frame.py:11617, in _reindex_for_setitem(value, index) 11613 if not value.index.is_unique: 11614 # duplicate axis 11615 raise err
11617 raise TypeError(
11618 "incompatible index of inserted column with frame index"
11619 ) from err
11620 return reindexed_valueTypeError: incompatible index of inserted column with frame index
- See error
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Environment If you are not using the latest version of the Docker imag:
- OS: [e.g. MacOSX, Windows, Ubuntu]
- Version [e.g. Big Sur, 10, 20.04]
Additional context Add any other context about the problem here.
def calculate_rsi(group):
rsi = RSI(group['close'])
return pd.Series(rsi, index=group.index)
rsi_values = prices.groupby(level='symbol').apply(calculate_rsi)
rsi_df = pd.DataFrame(rsi_values, columns=['rsi'])
rsi_df = rsi_df.reset_index(level=0).drop(columns=['symbol'])
prices = prices.merge(rsi_df, left_index=True, right_index=True)
from machine-learning-for-trading.
Related Issues (20)
- %load_ext zipline HOT 1
- problem in Long-Short Strategy, Part 1: Preparing Alpha Factors and Features HOT 1
- Daily historical return deciles HOT 1
- back testing is not working HOT 1
- Chapter 7 - Evaluating signals using alphalens HOT 1
- Chapter 8 02_backtesting_with_zipline HOT 1
- 01_parse_itch_order_flow_messages HOT 3
- Chapter 8 02_backtesting_with_zipline custom_loader not working HOT 1
- --
- installation get stuck / mamba env update -n ml4t -f installation/ml4t-base.yml
- No object named P in the file HOT 3
- Twitter data gone? Broken link in "data/twitter_sentiment.ipynb"
- Unable to replicate backtest performance | Chapter 8 02_backtesting_with_zipline HOT 1
- TypeError: download() got multiple values for argument 'start' when using pandas_datareader.data
- MultipleTimeSeriesCV, why does it iterate backwards in time? HOT 1
- KeyError: 'No object named quandl/wiki/prices in the file' HOT 1
- Install instructions for windows and linux suck - no offence
- Chapter 22_deep_reinforcement_learning Google Colab Python 3.10 HOT 4
- Chapter 22_deep_reinforcement_learning Google Colab Python 3.10 03_lunar_lander
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from machine-learning-for-trading.