Datasets:
Update Yelpdata_663.py
Browse files- 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 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|