问题
I have a data frame that includes a dictionary of codes and names. Some of the names are blank. I'm trying to fill those blanks based on other examples where the code matches a name. Thus far I have sorted into a df by code but can't figure out how to "fill in the blanks". Here is my code:
import pandas as pd
import json
from pandas.io.json import json_normalize
df = pd.read_json('data/world_bank_projects.json')
theme= pd.DataFrame([val for pair in df['mjtheme_namecode'].values for val in pair])
theme1 = theme.set_index('code').sort_index()
print(theme1)
name
code
1 Economic management
1 Economic management
1 Economic management
1 Economic management
1 Economic management
1 Economic management
1 Economic management
1 Economic management
1 Economic management
1 Economic management
1
1 Economic management
1
1 Economic management
1 Economic management
1
1 Economic management
1 Economic management
1 Economic management
1 Economic management
After I fill in I'd like to count (by either code or name which should be the same). I think I could just use value_counts for that, right?
来源:https://stackoverflow.com/questions/51754475/filling-a-series-based-on-key-value-pairs