我已經看過很多類似的問題,但我仍然無法讓大熊貓從另一個df的值列表中重命名df的行。我究竟做錯了什麼?熊貓重命名列表中的df行
def calculate_liabilities(stakes_df):
if not stakes_df.empty:
liabilities_df = pd.DataFrame(decimal_odds_lay.values * stakes_df.values) #makes df with stakes rows, decimal odds columns
stakes_list = stakes_df.to_dict()
print(stakes_list)
liabilities_df = liabilities_df.rename(stakes_list)
return liabilities_df
else:
print ("Failure to calculate liabilities")
stakes_list = stakes_df.to_dict()
給出以下字典:
{'Stakes': {0: 3.7400000000000002, 1: 5.5999999999999996, 2: 7.0700000000000003}}
我想liabilities_df的行分別更名爲3.7400000000000002,5.5999999999999996和7.0700000000000003。
不清楚您的要求,請查看文檔瞭解如何使用重命名https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rename.html –