我有一个混合数据类型的数据帧,我想改变str单元格的值(每个单元格由两个字母加上三个数字组成),这样不均匀的数字变成偶数,但数字会减少。AB123应该变成AB122,而不改变它前面的字母。你知道吗
下面是一个混合类型的数据帧示例:
df = pd.DataFrame({'Opportunity':['AB122','AB123','AB125', 'AB124'],
'Quantity': [2, 3, 4, 1],
'Member': ["AACC", "AACC", "AACC", 'DDEE']})
print (df)
Opportunity Quantity Member
0 AB122 2 AACC
1 AB123 3 AACC
2 AB121 4 AACC
3 AB120 1 DDEE
我希望结果是:
print (df2)
Opportunity Quantity Member
0 AB122 2 AACC
1 AB122 3 AACC
2 AB120 4 AACC
3 AB120 1 DDEE
下面是使用pandas的^{} 访问器进行的单向切片,将^{} 减去2得到整数部分,然后使用^{} 连接回列:
输入数据帧:
尝试:
现在:
是:
输出:
相关问题 更多 >
编程相关推荐