I have two dataframes.
[2500 rows x 4 columns]
Kundenname Adresse Ort PLZ
0 Amt Nortorfer Land Niedernstraße 6 Nortorf 24539.0
1 Nord GmbH Heilbadstr. 85 Münster 24529.0
2 Vertrieb GmbH Straße 4 Kassel 31117.0
.......
[1900 rows x 38 columns]
0 1 2 3 4 5 ... 32 33 34 35 36 37
0 (0 118 1999 2117) None None ... None None None None None None
1 (1 2000) None None None ....
....
The result should be like this:
Kundenname Adresse Ort PLZ
0 Amt Nortorfer Land Niedernstraße 6 Nortorf 24589.0
118 Amt Nortorfer Land Niedernstraße 6 Nortorf 24589.0
1999 Amt Nortorfer Land Niedernstraße 6 Nortorf 24589.0
2117 Amt Nortorfer Land Niedernstraße 6 Nortorf 24589.0
1 ......
2000 ......
etc.
I just did it with df.loc[[9,118,1999,2117]] but I need a loop or something that I don't have to type in manually.
When df1 is your dataframe with your address data, and df2 is your index dataframe as such:
You can rewrite your index_dataframe (df2) using melt:
This will give you the following result:
You can use this to merge with your df1:
Result:
If df2 really contains parentheses, as Mr. T asked, you should remove these first of course. Assuming all your df2-values are string, this would mean doing something like: