
来自以下数据框(df):
|------------+--------------------+-------------| | child_code | child_name | parent_code | |------------+--------------------+-------------| | 900 | world | 0 | | 920 | south-eastern asia | 900 | | 702 | singapore | 920 | |------------+--------------------+-------------|
我想生成这个数据框:
在线订餐系统源码,提供给设计人员参考一个小型的在线订餐管理系统源码,采用三层模式开发,代码注释详细前台可以进行用户注册、菜单管理及订餐后台管理员可以进行菜单管理、新闻管理、菜肴管理、用户管理操作数据库采用的是Sql2005(由于数据库在App_Data下,如果装了Sql2005数据库会自动配置)
0
|------------+--------------------+-------------+--------------------| | child_code | child_name | parent_code | parent_name | |------------+--------------------+-------------+--------------------| | 900 | World | 0 | | | 920 | South-Eastern Asia | 900 | World | | 702 | Singapore | 920 | South-Eastern Asia | |------------+--------------------+-------------+--------------------|``` How could I make the equivalent of an MS Excel `vlookup` to produce the `parent_name` column?
您可以使用series.map:
import pandas as pd
import numpy as np
data = {'child_name': {0: 'World', 1: 'South-Eastern Asia', 2: 'Singapore'},
'child_code': {0: 900, 1: 920, 2: 702},
'parent_code': {0: 0, 1: 900, 2: 920}}
df = pd.DataFrame(data)
df['parent_name'] = df['parent_code'].map(df.set_index('child_code')['child_name'])
df
child_name child_code parent_code parent_name
0 World 900 0 NaN
1 South-Eastern Asia 920 900 World
2 Singapore 702 920 South-Eastern Asia
以上就是如何在单个数据帧内进行vlookup?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号