Convert Categories Feature to numbers

import pandas as pd


if __name__ == '__main__':
mapping = {
"Class0": 0,
"Class1": 1,
"Class2": 2,
"Class3": 3,
"Class4": 4,
"Class5": 5
}
df = pd.read_csv("../input/train.csv")
# df.loc[:, "catagory"] = df.catagory.map(mapping)
df.loc[:, "catagory"] = df["catagory"].map(mapping)
上一篇:pandas取dataframe特定行/列


下一篇:pandas数据索引之loc、iloc、ix详解及实例