您好我试图替换两者的分数'得分1'和'得分2'。有时他们打印随机数。
正确替换字符串,但不是整数。
import pandas as pd
raw_data = {
"city" : ["new york", "Sydney", "miami", "Rome", ],
"rank": ["1st", "2nd", "2", "3"],
"score1": [33, 48, 25, 33],
"score2": [33, 48,33, 48]
}
df = pd.DataFrame(raw_data,
index = pd.Index (['a', 'b', 'd', 'e'], name = 'letter'),
columns = pd.Index(['city', 'rank', 'score1', 'score2'], name='attributes'))
df['score1'].replace([33, 48, 25, 33], [1,2,3,4], inplace=True)
df['score2'].replace([33, 48,33, 48], [1,3,4,5], inplace=True)
print(df)