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 27, 2020 in Python by Olaleye
• 120 points
3,233 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 15, 2020 by Abhishek Shingadiya

Related Questions In Python

0 votes
0 answers

But when I run this, I get NameError: name 'alphabeta' is not defined error. How to solve this?

tree = [[[5, 1, 2], [8, -8, ...READ MORE

Sep 6, 2020 in Python by MUHAMMAD
• 160 points

retagged Sep 7, 2020 by Gitika 1,002 views
0 votes
1 answer

when I run this, I get NameError: name 'state' is not defined error. How to solve this?

Hi@MUHAMMAD, I tried to run the exact code ...READ MORE

answered Sep 8, 2020 in Python by MD
• 95,440 points
2,475 views
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

edited Oct 7, 2021 by Sarfaraz 15,584 views
0 votes
0 answers

What do the three different types of brackets in Python code mean? I'm not sure if this is right, so if I'm wrong, please tell me:

[] - Normally used for dictionaries, list items () - ...READ MORE

Sep 11, 2023 in Python by Satyawrat
• 460 points
143 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,210 points
13,019 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, 2020 in Python by rahul
• 360 points
41,440 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
6,788 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
6,374 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 20, 2019 in Python by Noel Deepak Palle
5,530 views
–1 vote
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP