import pandas as pd
# original data-frame
df = pd.DataFrame([{"name":"john", "type":"", "age":"12", "location":"so"},
{"name":"jane", "type":"", "age":"12", "location":"so"}])
# convert existing dict to array of dict's
data = {"james":"20", "rich":"30"}
new_df = pd.DataFrame([{"name":k, "age":v} for k, v in data.items()])
# use data-frame append to add to existing df, missing values will be filled with NaN
df = df.append(new_df, ignore_index=True)
print(df)
输出
age location name type
0 12 so john
1 12 so jane
2 20 NaN james NaN
3 30 NaN rich NaN
输出
相关问题 更多 >
编程相关推荐