Untitled

mail@pastecode.io avatar
unknown
python
a year ago
530 B
6
Indexable
Never
import pandas as pd

data = pd.read_csv("test.csv")

template = {
    "name": [None],
    "age": [None],
    "color": [None]
}

df = pd.DataFrame()

for index, row in data.iterrows():
    row_data = {
        "name": row["name"],
        "age": row["age"],
        "color": template["color"][0]
    }
    row_df = pd.DataFrame(row_data)
    df = pd.concat([df, row_df])

# The resulting DataFrame df will have the values from the CSV with missing values
# in the "color" column filled in from the template.