首页 > 解决方案 > 使用 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.

标签: factor-analysis

解决方案


推荐阅读