0

i am trying to write a code that filters a json file into two columns using Pandas in python. after the filter has been done, i want to create a loop that would add the items in the column to be added to a list called review

import pandas as pd

reviews = []
df = pd.read_json('Books_small.json', lines=True)

data = df[['reviewText', 'overall']]

for b in data:
   reviews.append(b)

print(len(reviews))
petezurich
  • 9,280
  • 9
  • 43
  • 57

1 Answers1

0

I can suggest something like that :

If your data frame "data" is equal to

     reviewText       overall
0   Doesn´t work     MongoDB
1   Very good        Python

CODE

reviews = [] 
for i in range(len(data)):
    reviews.append([data.reviewText[i],data.overall[i]])

print(len(reviews))
print('\n')
print(reviews)

Output

2


[['Doesn´t work ', 'MongoDB'], ['Very good ', 'Python']]

Kevin Mukuna
  • 149
  • 1
  • 6
Datexland
  • 119
  • 4