1

Below is my JSON data that I am trying to convert into CSV.

{
  "account_number": "xxxx", 
  "actual_reading_current": "14581", 
  "actual_reading_previous": "13925", 
  "address": "asdsa3"
}

My code thus far,

data_file=pd.read_json('E:\\invoice\\output\\response.json')
    data_file.to_csv("try.csv",index=False)

One drawback is that it imports all the columns into csv, however, I want only the 1st and 2nd columns to be imported. Am I missing something here?

new code

data_file=pd.read_json('E:\\invoice\\output\\response.json')
    data_file.to_csv("try.csv",index=False,columns=['account_number'])

in my output its showing multiple time but in my json its only 1 time

enter image description here

6
  • Try: data_file.to_csv("try.csv", index=False, columns=['account_number', 'actual_reading_current']) Commented Jan 8, 2021 at 12:10
  • It doesn't look like read_json supports importing individual columns. Have you tried deleting the columns you don't need? Commented Jan 8, 2021 at 12:11
  • @PApostol yes it worked thanks, but i have one more problem Commented Jan 8, 2021 at 12:16
  • @PApostol in my csv file its showing multiple times Commented Jan 8, 2021 at 12:17
  • @PApostol lemme update my ques Commented Jan 8, 2021 at 12:17

0

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.