将值与python数据帧元素进行比较并打印

2024-09-28 21:55:52 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个程序,我已经计算了置信区间,然后我试图比较数据帧的值,并试图打印在上限和下限内的记录。你知道吗

%matplotlib inline
import numpy as np
import pandas as pd
import scipy.stats as stats
import matplotlib.pyplot as plt
df = pd.read_csv('/Users/amuly/Desktop/Student_Weight_Status_Category_Reporting_Results__Beginning_2010.csv')


#confidence interval for number of obese
margin=df["NO. OBESE"].sem()*1.96
upper_limit=df["NO. OBESE"].mean()+margin
lower_limit=df["NO. OBESE"].mean()-margin
print(lower_limit,upper_limit)

我得到正确的输出直到这里。。。你知道吗

下一步,我试图只得到那些在我的置信区间内的值

错误是-序列的真值是模糊的。使用a.empty、a.bool()、a.item()、a.any()或a.all()

if (df["NO. OBESE"]>=lower_limit) & (df["NO. OBESE"]<=upper_limit):
    correlate_data=pd.DataFrame(df)

我是新来的熊猫。求你了救命啊。谢谢


Tags: csvnomarginimportdfmatplotlibasstats