2016-03-07 16 views
-2

我想比较2值的结果,但我不知道这里发生了什么。熊猫如果/真理陈述值错误

# Read items into Dataframe and count the number of rows there is. 
df_csv = pandas.read_csv('dataset.csv', index_col=False, header=None) 
print(len(df_csv.index)) 

# Creating Session to count the number of rows there are in the SQL file 
Session = sessionmaker(bind=engine) 
session = Session() 
# Getting count 
meta = MetaData() 
table_to_count = Table('Database count details', meta, autoload=True, 
         autoload_with=engine) 
df_sql = session.query(func.count(table_to_count)).scalar() 
print(df_sql) 

# Perform logic test 
if df_csv <= df_sql: 
print("sql is less than csv") 

elif df_csv >= df_sql: 
print("CSV is current with sql") 

不过,我得到的错误是ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

我提到了一些计算器其他问题,但我仍然没能解决这个问题。你怎么看?

编辑

print(len(df_csv.index))将返回值3984

print(df_sql)将返回3982

所以我想这些2个数字进行比较。

+0

'if'不明白对数组布尔操作,因为错误状态一样,如果你有1或你阵列中的所有积极条件,所以你需要决定你是否正在寻找1个或更多的正面匹配,例如'if(df_csv <= df_sql).all():'等等。 – EdChum

+0

你认为'df_csv <= df_sql'是什么意思? – Goyo

+0

@Goyo我编辑了我的问题。希望能帮助到你? –

回答

0

您必须添加len

if len(df_csv) <= df_sql: 
    print("sql is less than csv") 
elif len(df_csv) >= df_sql: 
    print("CSV is current with sql") 

但我认为你需要:

if len(df_csv) > df_sql: 
    print("sql is less than csv") 
elif len(df_csv) == df_sql: 
    print("CSV is current with sql") 
+0

对不起,但我不明白这是如何回答我的问题。我尝试了你的方法,但是我仍然无法使逻辑测试正常工作 –

+0

这会返回一个错误消息''int'类型的对象没有len()' –

+0

对不起,我认为是错字。 – jezrael