Skip to content
Advertisement

saving appended list/dictionary to pandas dataframe

I am working on a code like below, which slices the address column. For this I have created a dictionary and created an empty list final to append all the pre processing.see code

JavaScript

After preprocessing I am appending the empty list. Now, I want to update the df_dict with the final list. and convert the df_dict to pandas dataframe.

sample out put:

JavaScript

Your help will be greatly appreciated.

Thanks in advance

Advertisement

Answer

You can operate directly on your df using str.split and apply to re-join the last 3 segments:

JavaScript

Output:

JavaScript

Edit: converting your df to a dict and back is a waste of resource. You can implement your calculations in a functions and use apply:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement