54822 105
我有如下所示的四列数据。列1中存在一些值,列1中的一些值再次在列3中重复。我想将列1与列3合并,同时从列3中删除重复项。我还想保持列的顺序。列1与列2相关联,列3与列4相关联,所以如果我能在归并过程中将列1的项移动到列2,将列3的项移动到列4,那就太好了。如有任何帮助,不胜感激。
输入表:
将输入表分成左右两部分后,我们可以很简单地使用布尔索引将左手项与不重复的右手项连接起来:
import pandas as pd
# this initial section only recreates your sample input table
from io import StringIO
input = pd.read_table(StringIO("""| Item | Price | Item | Price |
|-------|-------|------|-------|
| Car | 105 | Truck| 54822 |
| Chair | 20 | Pen | 1 |
| Cup | 2 | Car | 105 |
| | | Glass| 1 |
"""), ' *| *', engine='python', usecols=[1,2,3,4], skiprows=[1], keep_default_na=False)
input.columns = list(input.columns[:2])*2
# now separate the input table into the left and right part
left = input.iloc[:,:2].replace("", pd.NA).dropna().set_index('Item')
right = input.iloc[:,2:] .set_index('Item')
# finally construct the output table by concatenating without duplicates
output = pd.concat([left, right[~right.index.isin(left.index)]])
Price
Item
Car 105
Chair 20
Cup 2
Truck 54822
Pen 1
Glass 1
相关内容
- 如何将vector中每一个顺序递增的序列存储为新的vector
- 使用用户输入和numpy数组创建一个顺序数字计数器
- 我在python中的真值表中出现了一个顺序错误
- 按两列排序,但有一个顺序
- 是否有一个顺序,Pyomo,pyomo-extras和spyder需要与conda一起安装?
- postgre(SQL) 创建一个顺序的最后一个事务表
- 有哪些算法可以使用特定函数从数组的一个顺序转到另一个顺序?
- 使用 php 正则表达式从 SQL 查询中删除最后一个顺序依据子句
- 如何根据一定数量的连续零值对数据帧进行分段,并在 R 中给它们一个顺序
- 使用预训练模型并创建另一个顺序模型
- 如何使 PrimaryKey 以一个顺序为多个表生成 ID
- r语言 - expect_equal() 按一个顺序传递参数,如果交换参数,则失败
- 来自 MySQL 查询的响应按一个顺序返回键,但使用 Python 以不同的顺序保存
- 是否有一个类似 LinkedHashMap 的类,其中 PUT 最后的条目也是最后一个顺序?
- 将一个 RxJS 可观察结果传递到下一个顺序可观察量
- 在 Javascript 上给定一个顺序数组的对象顺序数组
- 宏变量以任何一个顺序SAS包含另一个子字符串
- 将输入层与另一个顺序模型一起传递到自定义损失函数中
- R:为给定列的每个唯一值创建一个顺序计数器
- tt -sql-更新客户cubtiserID(字母数字)的列表,其下一个顺序
最新更新
- Textarea Label in Form: Error: Label元素的for属性的值必须是一个非隐藏表单控件的I
- 如何在没有源文件的情况下使用XSL创建XML
- 通过指针在实例上实现类型的调用函数
- 在批处理脚本中替换而不是添加前缀
- 如果类没有初始化,c++编译器会生成一个defctor吗?
- 在我的代码中没有得到任何方程的答案,我的按钮进入我的字段
- vsto Outlook插件在Outlook 2016和Office 365中的行为不同
- npm install不会在我的React项目中安装任何node模块
- 用两次检查遍历两个列表
- 将图像转换为RGB格式的文本文件,格式为三逗号分隔
- 我正试图找到一种方法将TimeSpan变量转换为秒的整数量
- FCM云消息传递验证令牌
- C多重间接
- 显示数组中元素的倒计时。setInterval 不会导致延迟。最后一个元素立即显示
- sveltekit:等待来自+服务器的数据.t加载函数
- JQuery是:检查每次点击返回两个值
- RxJS中具有共享结果的请求队列
- Beautifulsoup如何添加一些东西到列,如果元素没有显示
- 在Jekyll blog中按2D位置(距离)搜索
- Robocopy在复制过程中向文件名添加日期
- c -间接递归的用例
- 如何将日期对象转换为格式(DD-MM-YYYY)
- 如何从没有使用python硒链接的网站下载文件?
- 用错误处理循环捕获用户输入的最佳方法
- 如何使用内部连接在php发送值从下拉菜单到数据库的两个不同的表
- 我如何得到一个状态的IISreset - true,如果它是启动和false,如果它是停止
- 如何复制列标题"Testing"的列
- 读取文件夹中的多个DOCX文件到多个dataframe时出错
- 无法下载InceptionV3 Keras
- 如何打印数据在模板django的一个不同的表由外键连接?
热门标签:
javascript python java c# php android html jquery c++ css ios sql mysql arrays asp.net json python-3.x ruby-on-rails .net sql-server django objective-c excel regex ruby linux ajax iphone xml vba spring asp.net-mvc database wordpress string postgresql wpf windows xcode bash git oracle list vb.net multithreading eclipse algorithm macos powershell visual-studio image forms numpy scala function api selenium