Python convert string of dictionary to dataframe

Viewed 33

I have a large string which has data in the following format:

str = '{"Item":"0","ADDRESS_ON_URL":"702-hartman-st-houston-tx-77007"},{"Item":"1","ADDRESS_ON_URL":"818-reinicke-st-houston-tx-77007"}'

I am looking to create a dataframe of the above data with desired output as following:

Item    ADDRESS_ON_URL
 0      702-hartman-st-houston-tx-77007
 1      818-reinicke-st-houston-tx-77007

I am not even sure how to approach the above.

TIA

1 Answers

Use pd.read_json() with lines=True:

s = '{"Item":"0","ADDRESS_ON_URL":"702-hartman-st-houston-tx-77007"},{"Item":"1","ADDRESS_ON_URL":"818-reinicke-st-houston-tx-77007"}'

df = pd.read_json(s, lines=True)
print(df)

Prints:

   Item                    ADDRESS_ON_URL
0     0   702-hartman-st-houston-tx-77007
1     1  818-reinicke-st-houston-tx-77007
Related