如何将多组列转换为熊猫中的单列?
我想将dataFrame( azi_0,azi_0,dist_0 )转换为dataframe( df )中的dist_47 )如 new_df 吗?
Azi = [f"Azi_{i}" for i in range(47)]
dist = [f"Dist_{i}" for i in range(47)]
:
current_sim_az_obj1 | current_sim_distance_r_obj1 | Azimuth | 距离 |
---|---|---|---|
-60 | 3.950372041 | -59.73007665 | 0 |
-60 | 6.950372041 | “ | 输出 |
, | -59.89004647 | ||
8.950372041- | | 7.765 | |
| new_df | 预期 59.64009363 | 8.345 |
-60 | 8.950372041 | -59.58010495 | 8.425 |
-60 | 8.950372041 | -59.58010495 | 8.425 |
-55 | 2.38397709 | -55.06095763 | 3.14 |
-55 | 2.38397709 | -55.21092934 | 3.065 |
-55 | 2.38397709 | -55.21092934 | 3.065 |
-55 | 2.38397709 | -55.2609199 | 3.03 |
-55 | 2.38397709 | -55.2609199 | 3.03 |
-55 | 2.38397709 | -55.2609199 | 3.03 |
-55 | 2.38397709 | -55.2609199 | 3.03 |
-55 | 2.38397709 | -55.03096329 | 3.105 |
-55 | 2.38397709 | -55.03096329 | 2.38397709 |
-55 | 2.38397709 | -55.27091802 | 3.12 |
-55 | 2.38397709 | -55.27091802 | 3.12 |
-5555 | 3.09 | | -55.8508086 |
| | | |
| | | |
| 2.38397709 | -55.8508086 | 3.09 |
-55 | 2.38397709 | -55.57086142 | 3.065 |
-55 | 2.38397709 | -55.57086142 | 3.065 |
如何将几列结合到单列中?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您本质上是在询问如何将某些DF列的值合并为一个列 - 您可以这样做:
随机创建的融合:
仅保留您使用的填充价值
来使您合并新的DF:
属性:受 Erfan的答案 to coalescce“> coalesce "> coalesce actor”> a>
您可能需要对于您所显示的数据。
You are essentially asking how to coalesce a values of certain df-columns into one column - you can do it like this:
which randomly creates:
To coalesce this and only keep filled values you use
to get a coalesced new df:
Attributation: inspired by Erfan's answer to Coalesce values from 2 columns into a single column in a pandas dataframe
You may need to Replacing blank values (white space) with NaN in pandas for your shown data.