|
|
发表于 2023-2-4 11:18:24
|
显示全部楼层
本帖最后由 isdkz 于 2023-2-4 11:20 编辑
编码问题:加个参数encoding指定编码
修改后的代码:
- import pandas as pd
- s = pd.Series([2065, 1120, 1044, 970, 908, 898, 652, 519])
- print("转换前:")
- print(s.info)
- print()
- # 转换的代码,实现原理是修改 pandas 用于格式化输出的源码把 fmt_index[1:] 和 fmt_values 调换,执行后永久生效,你可以看代码的实现过程,后面可以自己改回来
- import fileinput
- for line in fileinput.input(pd.io.formats.format.__file__, backup='.bak', inplace=1, encoding='utf-8'):
- if line != ' result = self.adj.adjoin(3, *[fmt_index[1:], fmt_values])\n':
- print(line, end='')
- else:
- print(' result = self.adj.adjoin(3, *[fmt_values, fmt_index[1:]])')
- pd.io.formats.format.__spec__.loader.load_module()
- print("转换后:")
- print(s.info)
复制代码 |
|