我想比较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().
我在stackoverflow上提到了一些其他问题,但我仍然无法解决这个问题。你觉得怎么样?
修改
print(len(df_csv.index))
将返回值3984
。
print(df_sql)
将返回3982
所以我想比较这两个数字。
答案 0 :(得分: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")