【发布时间】:2020-01-06 22:43:59
【问题描述】:
我想选择前两行来应用样式,但我无法选择它们。
我尝试了很多方法,但都行不通。
SH1.apply_style_by_indexes(indexes_to_style=SH1[SH1[0]], styler_obj=Styler(bold=True))
SH1.apply_style_by_indexes(indexes_to_style=SH1[SH1.loc[0]], styler_obj=Styler(bold=True))
SH1.style_alternate_rows(SH1[1], styles=Styler(font_color='green'))
文件 "C:\Users\dell\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\indexes\base.py", 第 2897 行,在 get_loc 中 return self._engine.get_loc(key) 文件“pandas_libs\index.pyx”,第 107 行,在 pandas._libs.index.IndexEngine.get_loc 文件中 “pandas_libs\index.pyx”,第 131 行,在 pandas._libs.index.IndexEngine.get_loc 文件 “pandas_libs\hashtable_class_helper.pxi”,第 1607 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item 文件 “pandas_libs\hashtable_class_helper.pxi”,第 1614 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 1
SH1.style_alternate_rows(SH1[1], styles=Styler(font_color='green')) 文件 "C:\Users\dell\AppData\Roaming\Python\Python37\site-packages\StyleFrame\style_frame.py", 第 109 行,在 getitem 中 返回 Series(self.data_df.getitem(item)) 文件“C:\Users\dell\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\框架.py", 第 2980 行,在 getitem 中 indexer = self.columns.get_loc(key) 文件“C:\Users\dell\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\indexes\base.py”, 第 2899 行,在 get_loc 中 return self._engine.get_loc(self._maybe_cast_indexer(key)) 文件“pandas_libs\index.pyx”,第 107 行,在 pandas._libs.index.IndexEngine.get_loc 文件 “pandas_libs\index.pyx”,第 131 行,在 pandas._libs.index.IndexEngine.get_loc 文件 “pandas_libs\hashtable_class_helper.pxi”,第 1607 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item 文件 “pandas_libs\hashtable_class_helper.pxi”,第 1614 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 1
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: python excel pandas dataframe styleframe