Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsi #301

Open
ishikabansal77 opened this issue Aug 4, 2023 · 1 comment
Open

rsi #301

ishikabansal77 opened this issue Aug 4, 2023 · 1 comment

Comments

@ishikabansal77
Copy link

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_msmgs

File ~\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_value

TypeError: incompatible index of inserted column with frame index

  1. 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.

@SUSHANTH009
Copy link

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_msmgs

File ~\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_value

TypeError: incompatible index of inserted column with frame index

  1. 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants