[英]writing expression in python: multiply string to int
尝试
formula = ""
# looping through tuples of (x, 1) (y, 2) (z, 3)
for val, var in zip(df1.values,df2.values):
# formatting the value and variable in the current tuple
# and appending to the initially empty formula string
formula += "{}*{}+".format(val[0], var[0])
公式 = 公式[:-1]
这应该有效。
import pandas as pd
df1=pd.DataFrame([1,2,3])
df2=pd.DataFrame(["x","y","z"])
formula = '+'.join([f'{var[0]}*{val[0]}' for val, var in zip(df1.values,df2.values)])
print(formula)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.