gpt4 book ai didi

python - 如何在乘法和使用正确的 .replace 时避免重复

转载 作者:太空宇宙 更新时间:2023-11-04 09:59:43 24 4
gpt4 key购买 nike

我有一些数据,我想用 Nan 替换点 ...

但是当我乘以 ['Cost'] 列时,'Nan' 也会增加:

import pandas as pd
import numpy as np
df = pd.DataFrame([{'Name': 'Chris', 'Item Purchased': 'Sponge', 'Cost': 22.50},
{'Name': 'Kevyn', 'Item Purchased': 'Kitty Litter', 'Cost': 2.50},
{'Name': 'Filip', 'Item Purchased': 'Spoon', 'Cost': '...'}],
index=['Store 1', 'Store 1', 'Store 2'])
df.replace ('...', 'Nan', inplace =True)
df['Cost']*=10
df

如何让数字相乘?

最佳答案

不要使用字符串,而是使用 np.NaN

关于python - 如何在乘法和使用正确的 .replace 时避免重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44247305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com