# Problem importing dataset

I am new to machine learning and I am trying to build a classifier. My problem is that I am not able to import the dataset I need. In particular, I put my dataset in the Desktop and what I did is:

#pakages
import numpy as np
import pandas as pd
import jsonlines                   #edit

from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import *
from sklearn.naive_bayes import *
from sklearn.metrics import confusion_matrix, classification_report
from sklearn import svm

#for visualizing data
import matplotlib.pyplot as plt
import seaborn as sns; sns.set(font_scale=1.2)

%matplotlib inline

print('Libraries imported.')


now, after these imports I want to use the function

training_set = pd.read_json('\Desktop\training_dataset.jsonl')  #edit


to import my dataset. The problem is that what i get is:

ValueError                                Traceback (most recent call last)
<ipython-input-16-f789503c3c7c> in <module>

~\Anaconda3\lib\site-packages\pandas\io\json\_json.py in
read_json(path_or_buf, orient, typ, dtype, convert_axes, convert_dates,
keep_default_dates, numpy, precise_float, date_unit, encoding, lines,
chunksize, compression)
591
593     if should_close:
594         try:

715             obj =
self._get_object_parser(self._combine_lines(data.split("\n")))
716         else:
--> 717             obj = self._get_object_parser(self.data)
718         self.close()
719         return obj

~\Anaconda3\lib\site-packages\pandas\io\json\_json.py in
_get_object_parser(self, json)
737         obj = None
738         if typ == "frame":
--> 739             obj = FrameParser(json, **kwargs).parse()
740
741         if typ == "series" or obj is None:

~\Anaconda3\lib\site-packages\pandas\io\json\_json.py in parse(self)
847
848         else:
--> 849             self._parse_no_numpy()
850
851         if self.obj is None:

~\Anaconda3\lib\site-packages\pandas\io\json\_json.py in
_parse_no_numpy(self)
1091         if orient == "columns":
1092             self.obj = DataFrame(
dtype=None
1094             )
1095         elif orient == "split":

ValueError: Expected object or value


[EDIT] the file is a .jsonl file, but yet I don't know how to import the dataset because I cannot use .read_json ,I have tried this:

openfile=open('Desktop\training_dataset.jsonl')
df=pd.DataFrame(jsondata)
openfile.close()
print(df)


but gives me the following error message:

OSError                                   Traceback (most recent call last)
<ipython-input-28-2422c1a9a77b> in <module>
----> 1 openfile=open('Desktop\training_dataset.jsonl')
3 df=pd.DataFrame(jsondata)
4 openfile.close()
5 print(df)

OSError: [Errno 22] Invalid argument: 'Desktop\training_dataset.jsonl'


[EDIT 2] by doing as suggested, so:

with open("\Desktop\training_dataset.jsonl") as datafile:
dataframe = pd.DataFrame(data)


I again obtain another error message, which is:

OSError                                   Traceback (most recent call last)
<ipython-input-47-1365f26e6db5> in <module>
----> 1 with open("\Desktop\training_dataset.jsonl") as datafile:
3 dataframe = pd.DataFrame(data)

OSError: [Errno 22] Invalid argument: '\\Desktop\training_dataset.jsonl'


but I don' understand, because my dataset is placed in my desktop.

• I could reproduce the error when the input file is not a correct json. Did you make sure your input is correct? Oct 23 '19 at 15:55
• Given the error message, maybe check this stackoverflow question. Oct 23 '19 at 19:48

First check whether the file is json or not using the following; https://jsonlint.com/. Once you are confirmed the file is a json, use the below code to read it.

with open("training_dataset.json") as datafile:
dataframe = pd.DataFrame(data)


A jsonl file is simply a file where each line is a json object. So you can just deserialize each line as a json object and then build a DataFrame
import json