pandas - 如何仅使用特定列从现有 df 创建新 df
问题描述
我有一个称为匹配的数据框,其中包含以下列:
id,season,city,date,team 1,team 2,toss_winner,toss_decision,result,DL_applied winner,win_by_runs,win_by_wickets,player_of_match,venue,umpire 1,umpire 2, umpire 3
。
从这里我需要创建一个名为matches_compact的新数据框,它应该包含以下列:
id, season, date and winner
解决方案
matches_compact=matches[['id','season','date','winner']]
推荐阅读
- python-3.x - requests.exceptions.ConnectionError: HTTPConnectionPool(host='docker.for.linux.localhost', port=8000): url: /api/user 超出最大重试次数
- php - Drupal 7:防止 webform 保存 IP
- spring - 当 Spring 应用程序无法通过“'uriComponentContributors' 不能为空”异常启动时
- svelte - cleartimeout 不清除 setTimeout
- turnjs - 构建目录并尝试在turnjs4中创建索引页面
- git - Git[Hub] - 使用存储库作为依赖项
- vue.js - 在 Vuetify js 中如何获取选择值?
- logstash - 将 Logstash 数据写入文件,同时保留原始文件名
- c# - 使用 Linq 进行运行时排序和类型
- python - 无法打开 jupyter 笔记本:AttributeError:“模块”对象没有属性“DirEntry”