factor-analysis - 使用 factor_analyzer 时出错。指定索引传递的空数据
问题描述
使用 factor_analyzer 时出现以下错误。我能够从这里得到这个例子来工作。https://www.datacamp.com/community/tutorials/introduction-factor-analysis 我看到的主要区别是它们的值都是数字的。我的是字符串。
from factor_analyzer.factor_analyzer import calculate_bartlett_sphericity
chi_square_value,p_value=calculate_bartlett_sphericity(df)
chi_square_value, p_value
(-0.0, 0.0)
from factor_analyzer.factor_analyzer import calculate_kmo
kmo_all,kmo_model=calculate_kmo(df)
ValueError Traceback (most recent call last)
~\anaconda3\lib\site-packages\pandas\core\internals\managers.py in create_block_manager_from_blocks(blocks, axes)
1664
-> 1665 mgr = BlockManager(blocks, axes)
1666 mgr._consolidate_inplace()
~\anaconda3\lib\site-packages\pandas\core\internals\managers.py in __init__(self, blocks, axes, do_integrity_check)
148 if do_integrity_check:
--> 149 self._verify_integrity()
150
~\anaconda3\lib\site-packages\pandas\core\internals\managers.py in _verify_integrity(self)
325 if block.shape[1:] != mgr_shape[1:]:
--> 326 raise construction_error(tot_items, block.shape[1:], self.axes)
327 if len(self.items) != tot_items:
ValueError: Empty data passed with indices specified.
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-31-af263734b3bc> in <module>
1 from factor_analyzer.factor_analyzer import calculate_kmo
----> 2 kmo_all,kmo_model=calculate_kmo(df)
~\anaconda3\lib\site-packages\factor_analyzer\factor_analyzer.py in calculate_kmo(data)
143 corr_sum = corr.sum(0)
144 kmo_per_item = corr_sum / (corr_sum + partial_corr_sum)
--> 145 kmo_per_item = pd.DataFrame(kmo_per_item,
146 index=data.columns,
147 columns=['KMO'])
~\anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
495 mgr = init_dict({data.name: data}, index, columns, dtype=dtype)
496 else:
--> 497 mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
498
499 # For data is list-like, or Iterable (will consume into list)
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in init_ndarray(values, index, columns, dtype, copy)
232 block_values = [values]
233
--> 234 return create_block_manager_from_blocks(block_values, [columns, index])
235
236
~\anaconda3\lib\site-packages\pandas\core\internals\managers.py in create_block_manager_from_blocks(blocks, axes)
1670 blocks = [getattr(b, "values", b) for b in blocks]
1671 tot_items = sum(b.shape[0] for b in blocks)
-> 1672 raise construction_error(tot_items, blocks[0].shape[1:], axes, e)
1673
1674
ValueError: Empty data passed with indices specified.
解决方案
推荐阅读
- python - 将参数传递给回调
- javascript - 无法在我的 JavaScript 绘图板中更改颜色
- laravel - Laravel 将多个参数传递给控制器
- excel - 在 VBA 中行/列交叉点中的值为“是”时,将表中的行颜色变为绿色
- java - Apache FOP:添加 Apache FOP Maven 依赖项后的错误列表
- java - Web 与桌面应用程序的性能限制?
- javascript - aws Cognito UI 自定义未在反应 natvie 应用程序中更新
- loops - Ansible:如何遍历字典
- python - Pygame鼠标速度
- javascript - Knex 在 TypeScript 中的 OrderBy