我想創建一個功能,允許用戶選擇一個範圍,它會打印出範圍內的數字。但是,我一直使用我的代碼獲取空的DataFrame。誰能幫我?Python,熊貓 - 我怎樣才能在數據範圍內打印某些東西?
`進口大熊貓作爲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=="2"):
my_columns = ["Name", "City", "State", "Jan"]
your_sales = input("please enter the minimum sale: ")
your_sales = input("please enter the maxium sale: ")
print (df[my_columns][df.Jan>int(your_sales)][df.Jan<int(your_sales)])`
那麼首先你使用相同變量爲你的最小和最大範圍值'your_sales'被覆蓋,所以你應該使用不同的變量,然後你想'print(df.loc [(df.Jan> int(min_sales))&(df.Jan
EdChum
您正在將最小和最大銷售額保存到同一變量。它必須是兩個不同的變量。 –