Johnnyeee commited on
Commit
46d9432
1 Parent(s): 3bd21f9

Update Yelpdata_663.py

Browse files
Files changed (1) hide show
  1. Yelpdata_663.py +29 -22
Yelpdata_663.py CHANGED
@@ -30,6 +30,7 @@ import os
30
  from typing import List
31
  import datasets
32
  import logging
 
33
 
34
  # TODO: Add BibTeX citation
35
  # Find for instance the citation on arxiv or on the dataset repo/website
@@ -105,26 +106,32 @@ class YelpDataset(datasets.GeneratorBasedBuilder):
105
  citation=_CITATION,
106
  )
107
 
108
- def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
109
- urls_to_download = self._URLS
110
- downloaded_files = dl_manager.download_and_extract(urls_to_download)
111
-
112
- return [
113
- datasets.SplitGenerator(name=datasets.Split.BUSINESS, gen_kwargs={"filepath": downloaded_files["business"]}),
114
- datasets.SplitGenerator(name=datasets.Split.REVIEW, gen_kwargs={"filepath": downloaded_files["review"]}),
115
- ]
116
-
117
-
118
- def _generate_examples(self, filepath):
119
- """This function returns the examples in the raw (text) form."""
120
- logging.info("generating examples from = %s", filepath)
121
- with open(filepath, encoding="utf-8") as csv_file:
122
- reader = csv.DictReader(csv_file)
123
- for i, row in enumerate(reader):
124
- # Handle missing values for float fields
125
- for key, value in row.items():
126
- if value == '':
127
- # Assuming all fields that can be empty are floats; adjust as needed
128
- row[key] = None
129
- yield i, row
 
 
 
 
 
 
130
 
 
30
  from typing import List
31
  import datasets
32
  import logging
33
+ import pandas as pd
34
 
35
  # TODO: Add BibTeX citation
36
  # Find for instance the citation on arxiv or on the dataset repo/website
 
106
  citation=_CITATION,
107
  )
108
 
109
+
110
+ def _generate_examples(self, filepaths):
111
+ logging.info("Generating examples from = %s", filepaths)
112
+
113
+ # Load JSON files into pandas DataFrames
114
+ business_df = pd.read_json(filepaths['business'], lines=True)
115
+ review_df = pd.read_json(filepaths['review'], lines=True)
116
+
117
+ # Merge DataFrames on 'business_id'
118
+ merged_df = pd.merge(business_df, review_df, on='business_id')
119
+
120
+ # Filter out entries where 'categories' does not contain 'Restaurants'
121
+ filtered_df = merged_df[merged_df['categories'].str.contains("Restaurants", na=False)]
122
+
123
+ # Convert to CSV (optional step if you need CSV output)
124
+ # filtered_df.to_csv('filtered_dataset.csv', index=False)
125
+
126
+ # Generate examples
127
+ for index, row in filtered_df.iterrows():
128
+ # Handle missing values for float fields
129
+ for key, value in row.items():
130
+ if pd.isnull(value):
131
+ row[key] = None # or appropriate handling of nulls based on your requirements
132
+
133
+ # Yield each row as an example
134
+ yield index, row.to_dict()
135
+
136
+
137