i write this python to read dataset into panda data frame but im getting NameError: name 'true' is not defined. Below is the code:

0 votes
i write this python to read dataset into panda data frame but im getting NameError: name 'true' is not defined. Below is the code:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 25 23:57:39 2020
@author: OLATUNJI
"""
import pandas as pd
import gzip
def parse(path):
    g = gzip.open(path, 'rb')
    for l in g:
     yield eval(l)
def getDF(path):
    i = 0
    df = {}
    for d in parse(path):
        df[i] = d
        i += 1
    return pd.DataFrame.from_dict(df, orient='index')
fashion_data = getDF('Amazon_Fashion.json.gz')
beauty_data = getDF('All_Beauty.json.gz')
appliances_data = getDF('Appliances.json.gz')
arts_data = getDF('Arts_Crafts_and_Sewing.json.gz')
automotive_data = getDF('Automotive.json.gz')

frames = [fashion_data.reviewText[:1000],beauty_data.reviewText[:1000], \
          appliances_data.reviewText[:1000],arts_data.reviewText[:1000],\
          automotive_data.reviewText[:1000]]
complete_data = pd.concat(frames, keys = ['video','auto','musical','office','patio'])
labels = []
for i in range(5):
    labels += [i] * 1000
fashion_data,beauty_data,appliances_data,arts_data,automotive_data = [],[],[],[],[]
print(complete_data.loc['Fashion'])
Feb 26 in Python by Olaleye
• 120 points
160 views

1 answer to this question.

0 votes

change 


def parse(path):

  g = gzip.open(path, 'r')

  for l in g:

    name=b'"verified": \"true\",'

    l=l.replace(b'"verified": true,',bytes(name))

    name1=b'"verified": \"false\",'

    l=l.replace(b'"verified": false,',bytes(name))

    yield eval(l)

answered Mar 14 by Abhishek Shingadiya

Related Questions In Python

0 votes
1 answer

Python Error saying "NameError: global name 'true' is not defined"

It's a very small mistake. Change true ...READ MORE

answered Jun 17, 2019 in Python by Vinayak
3,206 views
0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 69,000 points
3,478 views
0 votes
3 answers

Python error "NameError: name 'sr' is not defined"

NameError: name 'xx' is not defined Python knows ...READ MORE

answered Mar 19 in Python by rahul
• 320 points
13,104 views
0 votes
1 answer

Python error "Python NameError: global name 'Thread' is not defined"

There is a built-in function with the ...READ MORE

answered May 31, 2019 in Python by Riya
1,524 views
–1 vote
1 answer

Python error saying "NameError: name 'email' is not defined"

you need to define the variable email READ MORE

answered Nov 29, 2019 in Python by Casper
• 160 points
1,455 views
0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 19, 2019 in Python by Noel Deepak Palle
1,221 views
0 votes
1 answer
+2 votes
0 answers
0 votes
0 answers

I am trying to click the button but it is not working and it is drop list ..

<a class="quickreports btn btn3d tbbtn" href="javascript:" style="position:static" ...READ MORE

Dec 1, 2019 in Python by anonymous
• 120 points
121 views