python-3.x - 使用其他行的值添加新行
问题描述
我有一个熊猫数据框。我想在特定位置添加一个新行,例如在第一行之后。我希望使用第 1 行和第 2 行中的值来分配新行中单元格的值,但前提是两行中的值都不等于零。
States Andhra Pradesh Bihar Chhattisgarh Delhi
1973-74 50.67 56.01 0 60.99
1977-78 69.66 57.45 0 95.85
1983 115.4 93.75 100 217.14
1993-94 288.7 218.3 130 605.22
import pandas as pd
import math
data1= pd.read_excel('C:\\Users\\3004\\Desktop\\Variables.xlsx',3,index_col = 0)
data1.loc[8] = math.exp(math.log(data1.loc['1977-78']/data1.loc['1973-74'])/4)*data1.loc['1973-74']
预期输出:
States Andhra Pradesh Bihar Chhattisgarh Delhi
1973-74 50.67 56.01 0 60.99
1975 54.87 56.37 0 68.29
1977-78 69.66 57.45 0 95.85
1983 115.4 93.75 100 217.14
1993-94 288.7 218.3 130 605.22
第 1975 行的第一个值是“EXP(LN(69.66/50.67)/4)*50.57”
但是,我收到一条错误消息"TypeError: cannot convert the series to <class 'float'>"
解决方案
推荐阅读
- javascript - 如何在 javascript 中使用列表 2 次
- html - 文章中图像下方的中心标题 CSS HTML
- shopify - 部分如何链接到 .liquid 文件?
- c - 读取系统调用:当输入的字节数超过计数参数时,多余的字节溢出到 shell 并作为下一个命令执行
- python - 没有从编码问题中得到正确的输出
- javascript - 超级方法示例
- python - Apache Beam:在 CombineFn 中访问 WindowParam
- angular - Angular 中 QuickBlox VideoChat 中的噪音和回声
- excel - excel在两个方向上制作一个依赖列表?
- javascript - 为什么我需要为 res.sendFile() 指定绝对路径而不是相对路径?