对熊猫来说比较新,并且遇到了上述错误。下面的伪代码描述了我在合并两个数据帧时试图获得的内容
在数据帧DF的行中,DF卧室等于1,数据帧DF“乘数”等于数据帧租金_1“乘数”
这是我迄今为止的代码:
#DataFrame DF:
df = pd.DataFrame([
['123 HorseShoe Dr', 'St Petersburg', 2],
['13 Circle Ct', 'Gulfport', 1],
['21 Barcelona Ave', 'Tarpon Springs', 1],
['2113 Marks Dr', 'Treasure Island', 1],
], columns=['Address', 'City', 'BedroomsTotal'])
df.fillna(0, inplace=True)
#DataFrame Rent_1
rent_1 = pd.DataFrame([
['TREASURE ISLAND', 17.4947],
['TARPON SPRINGS', 20.0018],
['TIERRA VERDE', 18.3793],
['SOUTH PASADENA', 18.4124]
], columns=['City', 'Multiplier'])
rent_1.fillna(0, inplace=True)
.set_index('City')
df.set_index('City')
joined = df.join(rent_1)
print(joined)
#Below is the code that is giving me an issue:
#df.loc['Multiplier'] = np.where(df['BedroomsTotal'] == 1), rent_1['Multiplier'])
np.where(df.loc[df['BedroomsTotal'] == 1], df['Multiplier'], rent_1['Multiplier'])
以下是回溯:
line 1856, in _setitem_with_indexer_missing
raise ValueError("cannot set a row with mismatched columns")
ValueError: cannot set a row with mismatched columns
在此方面的任何帮助都将不胜感激。提前谢谢
目前没有回答
相关问题 更多 >
编程相关推荐