gpt4 book ai didi

python - “.. in pandas..html.py .. self.fmt.col_space.items()” : AttributeError: 'NoneType' object has no attribute 'items'

转载 作者:行者123 更新时间:2023-12-05 03:51:19 26 4
gpt4 key购买 nike

我试图找出单词相似度计算中的错误。

def word_similarity_error_analysis(eval_df):
eval_df['distance_rank'] = _normalized_ranking(eval_df['distance'])
eval_df['score_rank'] = _normalized_ranking(eval_df['score'])
eval_df['error'] = abs(eval_df['distance_rank'] - eval_df['score_rank'])
return eval_df.sort_values('error')


def _normalized_ranking(series):
ranks = series.rank(method='dense')
return ranks / ranks.sum()

word_similarity_error_analysis(eval_df).head()

我收到这个错误:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/IPython/core/formatters.py in __call__(self, obj)
336 method = get_real_method(obj, self.print_method)
337 if method is not None:
--> 338 return method()
339 return None
340 else:

2 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in _repr_html_(self)
732 return buf.getvalue()
733
--> 734 max_rows = get_option("display.max_rows")
735 min_rows = get_option("display.min_rows")
736 max_cols = get_option("display.max_columns")

/usr/local/lib/python3.6/dist-packages/pandas/io/formats/format.py in to_html(self, buf, encoding, classes, notebook, border)
980 Whether the generated HTML is for IPython Notebook.
981 border : int
--> 982 A ``border=border`` attribute is included in the opening
983 ``<table>`` tag. Default ``pd.options.display.html.border``.
984 """

/usr/local/lib/python3.6/dist-packages/pandas/io/formats/html.py in __init__(self, formatter, classes, border)
57 self.col_space = {
58 column: f"{value}px" if isinstance(value, int) else value
---> 59 for column, value in self.fmt.col_space.items()
60 }
61

AttributeError: 'NoneType' object has no attribute 'items'



word1 word2 score ... distance_rank score_rank error
1041 hummingbird pelican -32.0 ... 0.000243 0.000244 2.434543e-07
2315 lily pigs -13.0 ... 0.000488 0.000487 4.016842e-07
2951 bucket girls -4.0 ... 0.000602 0.000603 4.151568e-07
150 night sunset -43.0 ... 0.000102 0.000103 6.520315e-07
2062 oak petals -17.0 ... 0.000435 0.000436 7.162632e-07

[5 rows x 7 columns]

我看到很多人都遇到过相同类型的错误。但是,找不到合适的解决方案。这段代码有什么问题?此外,错误后如何产生结果。在发生错误的地方看不到确切的行号。

(我正在使用 Google Colab 和 Pandas 1.0.5 版,以备不时之需)

最佳答案

我在使用相对标准的 Pandas 代码的 AWS SageMaker 笔记本 (Python3.6) 上遇到了同样的问题。我越来越怀疑这种现象与python-pandas版本不匹配有关,因为用Python3.7在本地notebook上同样的代码并没有复制异常。

我还没有确认这确实是问题,因为环境并不完全相同,但尝试在 python > 3.6 上使用相同的数据运行相同的代码。

关于python - “.. in pandas..html.py .. self.fmt.col_space.items()” : AttributeError: 'NoneType' object has no attribute 'items' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62972298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com