<jupyter_start><jupyter_text>Data Cleaning<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_json("/home/paritosh/Downloads/Intern/Paritosh_Bangalore_newZ_9.json")
df.columns<jupyter_output><empty_output><jupyter_text>removing extra from strings<jupyter_code>df.drop(['Unnamed: 0'], axis = 1,inplace=True)
df['price for one'] = df['price for one'].str.replace(r'\D', '')
df['price for one'].astype(str).astype(int)
df['ratings'] = df['ratings'].replace(r'-', np.NaN, regex=True)
df['ratings'] = df['ratings'].replace(r'New', np.NaN, regex=True)
df['ratings'].astype(str).astype(float)
df.columns<jupyter_output><empty_output><jupyter_text>removing duplicates<jupyter_code>duplicate = df[df.duplicated(['names', 'crusine'])]
index_names = duplicate.index
print(index_names)
df.drop(index_names, inplace = True)
duplicates = df[df.duplicated(['names', 'crusine'])]  # to chech dupicates have been removed
print(duplicates)
df.reset_index(inplace = True, drop = True)<jupyter_output><empty_output><jupyter_text>converting crusines into list<jupyter_code>list_1 =  df.iloc[:2,-5:-4]
print(list_1)
for i in range(len(df['crusine'])+1):
    list_of_crusines = df.iloc[:i,-5:-4].values.tolist()
    
    
df['crusines'] = list_of_crusines
df.drop(['crusine'], axis = 1,inplace=True)
mid = df['crusines']
df.drop(labels=['crusines'], axis=1, inplace = True)
df.insert(4, 'crusines', mid)
df.reset_index(inplace = True, drop = True)<jupyter_output><empty_output><jupyter_text>Removing K<jupyter_code>#df['No_Delivery_Reviews'].replace(r'-', np.nan, inplace=True)
df['Delivery_Reviews'].replace(0, np.nan, inplace=True)
df["Indexes"] = df["No_Delivery_Reviews"].str.contains('K')
fkk = df["Indexes"].index
print(df["Indexes"])
df['Indexes'][1]
index = []
for i in range(0,len(df['Indexes'])):
    if df['Indexes'][i] == True:
        index.append(i)
        print(i)
a = df.loc[index,'No_Delivery_Reviews']
print(a)
df.Val = df['No_Delivery_Reviews']
try:
    df.Val = df.Val.replace(r'[K]+$', '', inplace=True,regex=True).astype(float) * \
              df.Val.str.extract(r'[\d\.]+([K]+)', expand=False).fillna(1).replace(['K','M'], [10**3]).astype(int)
except AttributeError:
    pass
df['No_Delivery_Reviews']
df.reset_index(inplace = True, drop = True)<jupyter_output><empty_output><jupyter_text>removing empty menu<jupyter_code>dict_Veg_menu = df["Veg_menu"]
empty_Veg_menu = []
for i in range(len(df['Veg_menu'])):
    try:
        del dict_Veg_menu[i]['Recommended']
    except KeyError:
        empty_Veg_menu.append(i)
        pass
dict_Non_veg_menu = df["Non_veg_menu"]
empty_index = []
for i in range(len(df['Non_veg_menu'])):
    try:
        del dict_Non_veg_menu[i]['Recommended']
    except KeyError:
        empty_index.append(i)
        pass
df.drop(df.index[empty_index], axis=0,inplace=True)
df.reset_index(inplace = True, drop = True)<jupyter_output><empty_output><jupyter_text>Exporting<jupyter_code>df.to_csv('final.json')
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 921 entries, 0 to 920
Data columns (total 10 columns):
 #   Column               Non-Null Count  Dtype 
---  ------               --------------  ----- 
 0   links                921 non-null    object
 1   names                921 non-null    object
 2   ratings              801 non-null    object
 3   price for one        921 non-null    object
 4   crusines             921 non-null    object
 5   Veg_menu             921 non-null    object
 6   Non_veg_menu         921 non-null    object
 7   Delivery_Reviews     885 non-null    object
 8   No_Delivery_Reviews  921 non-null    object
 9   Indexes              885 non-null    object
dtypes: object(10)
memory usage: 72.1+ KB<jupyter_text>tasks done 1. removed unwanted columns  2. change data types of ratings and cost 3. removed all duplicated based on crusines  4. convert crusines into list 5. convert k into 1000 ( need to put it into new column) 6. removed recomended from the and empty dicts.<jupyter_code>df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.151077375122429, 'fraction_numerical': 0.021057786483839373, 'mean_word_length': 4.197201017811705, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '608888', 'license': 'MIT', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1494, 'n_words': 294, 'path': 'paritosh_Zomato_data_cleaning.ipynb', 'repo_name': 'paritoshtripathi935/Zomato_Scraping', 'size': '4084'}