python - 如何在“团队”列中洗牌“爱国者”和“小马”标签?(PYTHON)
问题描述
假设这是数据,我如何洗牌“团队”列中的标签“爱国者”和“小马队”并将其附加到新列?
Team Blakeman Prioleau Combined Pressure Drop
0 Patriots 11.50 11.80 11.650 0.850
1 Patriots 10.85 11.20 11.025 1.475
2 Patriots 11.15 11.50 11.325 1.175
3 Patriots 10.70 11.00 10.850 1.650
4 Patriots 11.10 11.45 11.275 1.225
5 Patriots 11.60 11.95 11.775 0.725
6 Patriots 11.85 12.30 12.075 0.425
7 Patriots 11.10 11.55 11.325 1.175
8 Patriots 10.95 11.35 11.150 1.350
9 Patriots 10.50 10.90 10.700 1.800
10 Patriots 10.90 11.35 11.125 1.375
11 Colts 12.70 12.35 12.525 0.475
12 Colts 12.75 12.30 12.525 0.475
13 Colts 12.50 12.95 12.725 0.275
14 Colts 12.55 12.15 12.350 0.650
解决方案
你在寻找这样的东西吗?
import pandas as pd
import numpy as np
df = pd.DataFrame({'Team': ['Patriots','Patriots','Colts'], 'Blakeman':[11.50,10.85,12.70]})
df['new_col'] = np.random.permutation(df['Team'].values)
df
Team Blakeman new_col
0 Patriots 11.50 Colts
1 Patriots 10.85 Patriots
2 Colts 12.70 Patriots
推荐阅读
- c# - 将datagridview中的整行设置为ReadOnly = false
- docker - nginx后面的identityserver4在AKS(azure kubernetes)中使用https&letsencrypt阻止mvcclient因某种原因设置cookie
- android - Kotlin corountines :注意:结束时间超过纪元:
- php - 在mysql查询中求和多个日期范围
- angular - 在用户输入角度 2 时更改 ng-select 组件的输入值
- mysql - 检索别名的基础列名
- asp.net-core - 如何在 ASP.NET Core Web API 响应中忽略 ResponseWrapper
- maven - 用于 java spring maven 应用程序的 Gitlab CI/CD
- javascript - fabric js - 如何检查模式是否应用于 svg
- c# - 在视图模型中有条件地更改显示名称