Python 从dataframe.min()系列对象中提取整数?
我试图使用Pandas计算dataframe列中的最小值,然后对变量运行一个求值语句(如果是这个,那么是那个)。但是,无法对序列对象求值。如何从熊猫系列对象中提取数值Python 从dataframe.min()系列对象中提取整数?,python,pandas,dataframe,series,Python,Pandas,Dataframe,Series,我试图使用Pandas计算dataframe列中的最小值,然后对变量运行一个求值语句(如果是这个,那么是那个)。但是,无法对序列对象求值。如何从熊猫系列对象中提取数值 for file_ in postFiles: df2 = pd.read_csv(file_, header=0, delimiter=';', usecols=[0,1,2]) ymax = df2[['xvalue']].max(numeric_only=True) y
for file_ in postFiles:
df2 = pd.read_csv(file_, header=0, delimiter=';', usecols=[0,1,2])
ymax = df2[['xvalue']].max(numeric_only=True)
ymin = df2[['yvalue']].min(numeric_only=True)
print(ymax)
print(ymin)
if ymax > ymin:
print ('hello')
这是我的代码示例
运行此操作时,我遇到以下错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
max
和min
返回一个Series
你想要数组中的标量值试试这个:ymax=df2[['xvalue']].max(numeric_only=True)[0]ymin=df2['yvalue'].min(numeric_only=True)[0]
Perfect@EdChum,正是我需要的答案-非常感谢你的快速回复max
和min
返回一个Series
你想要数组中的标量值试试这个:ymax=df2[['xvalue']].max(numeric_only=True)[0]ymin=df2['yvalue'].min(numeric_only=True)[0]
Perfect@EdChum,这正是我需要的答案-非常感谢你的快速回复!