我希望我的选择3能够解决。我想将4月,5月,6月的总和与每个账户的总和进行比较。 (列的总和与轴的总和比较)我不断得到系列长度必须匹配才能比较
import pandas as pd
if __name__ == "__main__":
file_name = "sales_rossetti.xlsx"
# Formatting numbers (e.g. $1,000,000)
pd.options.display.float_format = '${:,.0f}'.format
# Reading Excel file
df = pd.read_excel(file_name, index_col = 0, convert_float = False)
print ("Welcome to Rossetti's Sales program\n")
print ("1) Search by State")
print ("2) Search by Jan Sales")
print ("3) Search by Q2 sales")
print ("4) Exit")
my_option = input ("Please select a menu option:")
if (my_option=="3"):
my_columns = ["Apr","May","Jun"]
all_columns = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
your_sales = input ("Please enter your minimum sale: ")
print (df[my_columns].sum()<df[all_columns].sum(axis=1, skipna=None, level=None, numeric_only=True))'
错误讯息是:“ 文件“C:\ Users \ jay \ Anaconda3 \ lib \ site-packages \ pandas \ core \ ops.py”,第735行,在包装器中 提高ValueError('系列长度必须匹配才能比较')
ValueError:系列长度必须匹配才能比较“
答案 0 :(得分:0)
如果您打印出df[my_columns].sum()
和df[all_columns].sum(axis=1, skipna=None, level=None, numeric_only=True)
的结果,您可能可以自行调试。
我的猜测是因为你对skipna有不同的值,所以第一个系列已经删除了一些行,所以你无法直接比较它们。