python - Python中对多个Dataframes的操作

标签 python pandas dataframe

提供了数据框:

a = pd.DataFrame({'A':[1, 2]})
b = pd.DataFrame({'B':[2, 3]})
C = pd.DataFrame({'C':[4, 5]})

并列出 d = [A, C, B, B]

如何在帧值上编写数学运算 (((A + C) * B) - B) 以创建新的数据帧?

例如,结果是以下形式的框架:

e = pd.DataFrame({'E':[8, 18]})

最佳答案

IIUC:

In [132]: formula = "E = (((A + C) * B) - B)"

In [133]: pd.concat([a,b,C], axis=1).eval(formula, inplace=False)
Out[133]:
   A  B  C   E
0  1  2  4   8
1  2  3  5  18

In [134]: pd.concat([a,b,C], axis=1).eval(formula, inplace=False)[['E']]
Out[134]:
    E
0   8
1  18

关于python - Python中对多个Dataframes的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47382607/

相关文章:

python - 为什么我的 Firebase Firestore 查询不在 order_by 中?

python找到两个numpy数组的交点

python - 从列列表中的括号内提取数字

python - 从 Python 数据框的一列中的每一行中删除前 x 个字符

Python - 如何将列元素添加到带有计数器的列表中

python - 尝试使用变量更改 discord.Colour 时错误请求 400

python-2.7 - 如何使用python在python中绘制多索引数据框?

python - Pandas : count identical values per row

python - 用 1 替换 Python Pandas Dataframe 中的所有字符串类型

r - 获取数据框中各组的标准差