1

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 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

lines = True .. was the important trick here :) first I tried just read_json and it wasn't working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.