目前正在尝试收集一些关于熊猫和Matplotlib数据科学的知识
我想做什么
选择具有相应价格的邻里组租用私人房间(AirBnB)
问题
对于一列,我得到了正确的数据,但是对于其余的列,我得到了NaN值。感谢您的帮助,下面您可以找到一个代码片段和输出
ap_df = pd.DataFrame()
for neighbourhood_group in df['neighbourhood_group'].unique():
nbhg_df = df.copy()[df['neighbourhood_group']==neighbourhood_group]
nbhg_df[f"{neighbourhood_group}_Price"] = nbhg_df['price']
nbhg_df.set_index("id", inplace=True)
nbhg_df.sort_index(inplace=True)
if ap_df.empty:
ap_df = nbhg_df[[f"{neighbourhood_group}_Price"]]
else:
ap_df = ap_df.join(nbhg_df[f"{neighbourhood_group}_Price"])
ap_df
因此,我想我可以帮助你用另一个更简单和工作的例子,适合你的需要
输出:
相关问题 更多 >
编程相关推荐