Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pandas-基于另一个值的列值的反向符号_Python_Pandas - Fatal编程技术网

Python Pandas-基于另一个值的列值的反向符号

Python Pandas-基于另一个值的列值的反向符号,python,pandas,Python,Pandas,现在有谁能建议怎么做 目前我正在使用apply,但它显然要经过每个单元格,而且需要很长时间 标价-浮动 ordtype=str(“I”、“C”、“K”) 我希望ordtype列中的所有“C”和“K”值都为负值(它们当前为正值) 我现在使用的示例代码: final_lines["list-price"] = final_lines.apply(lambda x: x["list-price"]*-1 if x["ordtype"] !=

现在有谁能建议怎么做

目前我正在使用apply,但它显然要经过每个单元格,而且需要很长时间

标价-浮动 ordtype=str(“I”、“C”、“K”)

我希望ordtype列中的所有“C”和“K”值都为负值(它们当前为正值)

我现在使用的示例代码:

final_lines["list-price"] = final_lines.apply(lambda x: x["list-price"]*-1 if x["ordtype"] != "I" else x["list-price"])
尝试:

df.loc[df['ordtype'].ne('I'), 'list-price'] *= -1