你可以使用
.replace。例如:
>>> df = pd.Dataframe({'col2': {0: 'a', 1: 2, 2: np.nan}, 'col1': {0: 'w', 1: 1, 2: 2}})>>> di = {1: "A", 2: "B"}>>> df col1 col20 w a1 1 22 2 NaN>>> df.replace({"col1": di}) col1 col20 w a1 A 22 B NaN或直接在上
Series,即
df["col1"].replace(di, inplace=True)。



