我有一个包含有关植物数据的数据框。每个工厂的计算都有不同的指标。 我想排除其值小于0的观察值,但是由于某些原因,我会出错:
TypeError:|:“ str”和“ str”不支持的操作数类型
我不明白为什么会收到此错误,因为它都是计算变量。
这是我尝试排除负值的方法:
df_07=(df_indices.loc[df_indices['Hour'] == '7:00']) |(df_indices.loc[df_indices['Zhao 405-715'] > 0])
这是我的代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
df_plants = pd.read_csv('Data_plants_26_11_2019.csv')
df_Nit=pd.read_csv('chemometrics.csv')
df_plants.head()
#create new colum which contains aonly the hour using lambda
df_plants['Hour']=df_plants['time'].apply(lambda time: time.split(' ')[1])
df_plants['date']=df_plants['time'].apply(lambda time: time.split(' ')[0])
df_plants['NDVI']=(df_plants['801.03']-df_plants['680.75'])/(df_plants['801.03']+df_plants['680.75'])
df_plants['YU_index']=(6.272-0.912*df_plants['991.83']-1.251*df_plants['755.72']-1.248*df_plants['748.87']-1.345*df_plants['918.9']-1.362*df_plants['909.13']-1.333*df_plants['921.69']-1.255*df_plants['758.46']-1.356*df_plants['911.92'])
df_plants['Zhao 405-715']=(df_plants['404.86']/df_plants['714.74'])
df_indices=df_plants[['plant','date','Hour','Treatment','Line','NDVI','YU_index','Zhao 405-715']]
#select specific hour case
df_07=(df_indices.loc[df_indices['Hour'] == '7:00']) |(df_indices.loc[df_indices['Zhao 405-715'] > 0])
我的最终目标是从数据库中排除任何在计算出的变量之一中具有负值的观察结果。