python - Combining excel spreadsheets using dictionaries -


i've made simple example trying merge 2 spreadsheets. aim create spreadsheet 'name of city', 'state' , 'population' 3 columns. think way use dictionaries.

i've had go @ myself , have far.

code data

do know pandas package?

you can read data excel file dataframe pandas.read_excel , merge 2 dataframes on name of city column.

here's short example shows how easy merging 2 dataframes using pandas:

in [1]: import pandas pd in [3]: df1 = pd.dataframe({'name of city': ['sydney', 'melbourne'],    ...:                     'state': ['nsw', 'vic']})     in [4]: df2 = pd.dataframe({'name of city': ['sydney', 'melbourne'],    ...:                     'population': [1000000, 200000]}) in [5]: result = pd.merge(df1, df2, on='name of city') in [6]: result out[6]:   name of city state  population 0       sydney   nsw     1000000 1    melbourne   vic      200000 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -