Untitled
unknown
python
2 years ago
530 B
10
Indexable
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.
Editor is loading...