作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻求一些帮助,我有这个例子
numbers=['Sub1','Sub2','Sub3']
Value=[60,45,30]
Y = pd.Series()
for number,i in zip(numbers,Value):
Y[number]=math.cos(i)
print(Y)
我得到这个结果
Sub1 -0.952413
dtype: float64
Sub1 -0.952413
Sub2 0.525322
dtype: float64
Sub1 -0.952413
Sub2 0.525322
Sub3 0.154251
dtype: float64
但我希望得到的是
Sub1 -0.952413
Sub2 0.525322
Sub3 0.154251
或
-0.952413
0.525322
0.154251
因为我需要这些值来完成代码。谢谢BR初学者
最佳答案
试试这个:
list(zip(numbers,[f'"{math.cos(i):.6f}' for i in Value]))
[('Sub1', '"-0.952413'), ('Sub2', '"0.525322'), ('Sub3', '"0.154251')]
或者:
pd.DataFrame(list(zip(numbers,[f'{math.cos(i):.6f}' for i in Value])))
0 1
0 Sub1 -0.952413
1 Sub2 0.525322
2 Sub3 0.154251
关于python - 带 zip 的 For 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59400508/
我是一名优秀的程序员,十分优秀!