Python Dataframe 列匹配
我有 2 列 A & B. A 包含由“_”分隔的文本值,B 有一些与 A 相关的描述。
示例:
*Col Terms
AB_BCN_PRC About Bitcoin Price
AC_CR_STT Account credit Statement
A6_AT_MD Audi Automatic Model*
我需要映射 A 和 B,因此将来如果 A 中出现新值,它应该自动构建 B
示例:
*A B
AB_CR_STT About credit Statement*
任何想法或可能如何完成这件事?
I have 2 columns A & B. A contains text values separated by '_' and B has some description related to A.
Example:
*Col Terms
AB_BCN_PRC About Bitcoin Price
AC_CR_STT Account credit Statement
A6_AT_MD Audi Automatic Model*
I need to map A and B so in future if a new value comes in A it should frame B automatically
Example:
*A B
AB_CR_STT About credit Statement*
Any idea or possible ways to get this done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你能定义一个好的完整的映射字典(每个名字用_分隔作为键,这个名字代表的文本作为值),就可以很容易实现,最后我用pandas组合成你例子中的格式,也可以直接使用print,主要关注函数gen_terms,通过你提供的名称返回全文,你可以在此基础上根据你需要的功能进行扩展(确保你传入的名称中的每一项,由 _ 分隔,是您定义的在col_map中):
If you can define a good complete mapping dictionary (each name separated by _ as a key, the text represented by this name as a value), it can be easily implemented, and finally I used pandas to combine into the format in your example, you can also use print directly, the main focus on the function gen_terms, by the name you provide to return the full text, you can expand on this basis according to the functions you need(Make sure that each item in the name you pass in, separated by _, is the one you defined in the col_map):