import pandas as pd
# 读取Excel文件
df = pd.read_csv('calparm.csv')
# 过滤无效数据
vehicle_scale = df[df['online_calibrated_flag'] == 1]["vehicle_scale"]
print('2', vehicle_scale)
print('3', vehicle_scale)
vehicle_scale2 = vehicle_scale[vehicle_scale>0.5]
print('4', vehicle_scale2)
# 计算方差
variance = vehicle_scale2.var()
mean = vehicle_scale2.mean()
std_dev = vehicle_scale2.std()
# 输出结果
print("全数据",'方差为:', variance ,'平均值',mean,'标准差',std_dev)
# 过滤重复数据
vehicle_scale2=vehicle_scale2.drop_duplicates();
variance2 = vehicle_scale2.var()
mean2 = vehicle_scale2.mean()
std_dev2 = vehicle_scale2.std()
# 输出结果
print("去重数据",'方差为:', variance2 ,'平均值',mean2,'标准差',std_dev2)
pandas库读取csv文件某一行并进行条件过滤计算平均值及其方差等
最新推荐文章于 2024-08-24 15:46:50 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)