python - 如何在数据框中的每 11 个位置插入 -1?
解决方案
也许你可以使用pandas.DataFrame.iloc
:
>>> import pandas as pd
>>> d = {'%UNWEIGHTED_ILI': [0.184361, 0.527357, 0.330384, 0.100392,
0.491726, 0.433408, 0.117853, 0.129628,
0.204399, 0.342965, 0.123456, 0.976543]}
>>> df = pd.DataFrame(data=d)
>>> df
%UNWEIGHTED_ILI
0 0.184361
1 0.527357
2 0.330384
3 0.100392
4 0.491726
5 0.433408
6 0.117853
7 0.129628
8 0.204399
9 0.342965
10 0.123456
11 0.976543
>>> df.iloc[::11, :] -= 1
>>> # df.iloc[11::11, :] -= 1 If you don't want -1 to be added to the first row
>>> df
%UNWEIGHTED_ILI
0 -0.815639
1 0.527357
2 0.330384
3 0.100392
4 0.491726
5 0.433408
6 0.117853
7 0.129628
8 0.204399
9 0.342965
10 0.123456
11 -0.023457
推荐阅读
- select - 选择语句通道示例
- scala - 初始化期间的Scala NullPointerException
- c# - OAuth 的自定义同意屏幕
- docker - Docker 版本 18.04.0-ce 忽略不支持的选项:network_mode
- macos - Mac OS 终端命令 如何区分 wlan 和以太网地址?
- java - java正则表达式解析
- jmeter - 如何在 HTTP 标头管理器中使用用户变量形式的 webdriver 采样器
- python - Spur spawn 没有向远程机器启动所有进程
- c++ - 英特尔 TBB -“InitializeCriticalSectionEx”:找不到标识符编译器错误
- python - Python 3 中的 Pandas to_csv 到 GzipFile 不起作用