我想打印那些item_pricefinal
介于item_price1
和item_price2
之间的行
这里是我正在运行的代码和数据集-
import pandas as pd
pd.set_option('display.max_columns', None) # Number of columns to be displayed
pd.set_option('display.width', None) # Max table width to display
pd.set_option('display.max_rows', None) # Max number of rows
pd.set_option('mode.chained_assignment', None) # Turn off SettingWithCopyWarning warning
data_list = <<Please read from here - https://1drv.ms/t/s!Aiw4HhkSppuhET8gSypP?e=y71rot
data_df = pd.DataFrame(data_list)
data_df.columns = ['item_date', 'item_price1', 'item_price2', 'item_pricefinal', 'itempricefinal-itemprice1', 'itempricefinal-itemprice2']
mask = data_df['item_pricefinal'].between(data_df['item_price1'], data_df['item_price2'])
对于每一行,输出都为false,尽管存在此条件保持良好的行
示例-在以下条目中,0.890624368082415介于0.90588和;0.86638,但是between
函数认为它不是,并在输出中打印false
['2020-03-09 00:00:00', 0.90588, 0.86638, 0.8906243680824152, 152.55631917584833, 242.44368082415147]
请允许我请求帮助以发现错误
在
data_df['item_pricefinal'].between(a,b)
和data_df['item_pricefinal'].between(b,a)
之间存在差异。顺序(a,b)或(b,a)很重要看起来
item_price2
比item_price1
低。所以正确的代码应该是在pd.between(left, right)、
left is left boundary
和right is right boundary
在这种情况下,您的示例将起作用
相关问题 更多 >
编程相关推荐