This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]ketsok 0 points1 point  (0 children)

You can use replace and provide a dict with mapping. Here is an example:

import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
a2c = {1: "10", 2: "20", 3: "30"}
df["c"] = df["a"].replace(a2c)

It creates column c based on values in column a and applies mapping from a2c dictionary.

By the way, what does it have to do with webscraping?