<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anushka Mehra on Medium]]></title>
        <description><![CDATA[Stories by Anushka Mehra on Medium]]></description>
        <link>https://medium.com/@anushkamehra16?source=rss-5e5d4d2278c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1yUMx6xotZvqrwTa.jpg</url>
            <title>Stories by Anushka Mehra on Medium</title>
            <link>https://medium.com/@anushkamehra16?source=rss-5e5d4d2278c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 21:04:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anushkamehra16/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Most Liked Restaurant Neighborhoods in New Delhi]]></title>
            <link>https://medium.com/@anushkamehra16/most-liked-restaurant-neighborhoods-in-new-delhi-d7d56aec4abf?source=rss-5e5d4d2278c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7d56aec4abf</guid>
            <dc:creator><![CDATA[Anushka Mehra]]></dc:creator>
            <pubDate>Thu, 30 Apr 2020 21:24:57 GMT</pubDate>
            <atom:updated>2020-04-30T21:24:57.059Z</atom:updated>
            <content:encoded><![CDATA[<p>New Delhi the capital city of India, is a hub of food of various cuisines. In this article, I will walk through the steps taken to cluster areas in Delhi with most liked restaurants. In this project, we also use Foursquare API to get information about the venues/ restaurants in these neighborhoods. Foursquare API is also used to fetch number of likes for each venue.</p><p><strong>Data Set Used:</strong></p><p>The data set used is obtained from Kaggle. The data set contains Neighborhood, Borough, Latitude and Longitude information for Delhi, India. The data can be downloaded from Kaggle at <a href="https://www.kaggle.com/shaswatd673/delhi-neighborhood-data">https://www.kaggle.com/shaswatd673/delhi-neighborhood-data</a>.</p><p><strong>Lets Code!</strong></p><p>Lets dive into the programming part. The entire notebook can be accessed here <a href="https://github.com/anushkamehra16/Coursera_Capstone/blob/master/Most%20Liked%20Restaurant%20Cluster%20in%20New%20Delhi.ipynb">https://github.com/anushkamehra16/Coursera_Capstone/blob/master/Most%20Liked%20Restaurant%20Cluster%20in%20New%20Delhi.ipynb</a></p><p>We start by importing main libraries like pandas, numpy, folium, KMeans, matplotlib. These are the basic libraries we need to proceed with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*BC5B0gfhS_VoNQ_A6x6Hzg.png" /><figcaption>Libraries to be imported</figcaption></figure><p>Next is to import the Delhi Neighborhood csv file into a pandas dataframe. This can be done using a single line of code in python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*YlMoJ7DbLt7jvJNvmuSNxA.png" /><figcaption>Reading data set into a pandas data frame</figcaption></figure><p>Now that we have the data frame ready, we will inspect the data frame. Extract the shape of the data frame i.e. number of rows and number of columns.</p><p>We are interested in only two Boroughs New Delhi and South Delhi. We create a subset to get neighborhoods for these two boroughs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*t5ueSzN3Suk9VnGjaktXfw.png" /><figcaption>Subset with Borough New Delhi</figcaption></figure><p>Similarly, subset with Borough is South Delhi. Again, check the shape of the data frame. We have 54 rows and 4 columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*eErCo4mqwuGc84jDVZC1lA.png" /></figure><p>Next, we plot Delhi Map using Folium library. The map created is an interactive map. We can set the initial zoom level for our map. To generate a map, we need latitude and longitude attributes for the location. This can be done using geocode’s Nominatim library where the input is our location name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*xuwBJttkkroV4l1x_tV0xg.png" /></figure><p>Now that we have New Delhi’s latitude and longitude values, we can create a map using Folim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*JcbK3aHnsjcj5CZAOgz2JQ.png" /></figure><p>The subset just created with New Delhi and South Delhi borough, its neighborhood values are plotted on the map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*CJ-xCLuDewwMzck6iI1QWA.png" /></figure><p><strong>Using FourSquare:</strong></p><p>To access FourSquare API, we need to create a developer account and get Client_ID and Client_Secret and verison information, as it will be used in every API call.</p><p>Two API endpoints are used :</p><ol><li>Explore endpoint to get venues in neighborhoods</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*9Njd6N6rW_KOuUeiC2bbsA.png" /></figure><p>We obtain the results in a json format and transform it into a pandas data frame with only attribute information of our interest. The venueID is used as an input to the likes API endpoint.</p><p>2. Likes endpoint to get likes count for each venue.</p><p>Likes API extracts number of likes for a venue by using the venueID. We extract likes count for all food venues using this endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*7gt6PUbeJmRzLAzTFdMI3w.png" /></figure><p>We have the likes count for all food venues and we have their neighborhood information.</p><p>Next, we join the data frame containing likes count with delhiVenues data frame containing venue information like Neighborhood, Venue Latitude, longitude, category.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*5QA9rbSCearW_P-GW4TJIQ.png" /></figure><p>Further, this data frame is grouped on Neighborhood and mean is found for likes count. This new data frame will be used for clustering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*V0gAtkGDbWBN0dlKeYkRbA.png" /></figure><p><strong>Clustering:</strong></p><p>To find the optimal value for K, we use elbow method. In this, Kmeans algorithm is run against a range of values for K. Here, our range is 1 to 10. The value at which the graph changes its shape to flatten out, is usually adopted as the optimal value for K.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*wBdwELSO-Wn2qhdzLvur4Q.png" /><figcaption>Optimal value for K</figcaption></figure><p>From the graph above, our optimal value for K is 3. So, using K = 3, a new model is generated to produce 3 clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*h9N8Wfo70VXJcgsZG2oJKA.png" /><figcaption>Fit value K = 3</figcaption></figure><p>After running this, we have obtained 3 clusters. These clusters define neighborhoods with most liked venues/ restaurants.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*zuVkYuNMxHTzMbqReuwJag.png" /><figcaption>Cluster 2</figcaption></figure><p>As seen above, cluster 2 has highly liked neighborhoods. Similarly, we can see values for cluster 1 and 3.</p><p>At last, we concatenate Borough column with our cluster data frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*Nz3dBvJVpZMhGjt_mfLuZw.png" /></figure><p>This way, we have obtained clusters in New Delhi of highly liked places.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7d56aec4abf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting to SQL Database using SQLAlchemy in Python]]></title>
            <link>https://medium.com/@anushkamehra16/connecting-to-sql-database-using-sqlalchemy-in-python-2be2cf883f85?source=rss-5e5d4d2278c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2be2cf883f85</guid>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas]]></category>
            <dc:creator><![CDATA[Anushka Mehra]]></dc:creator>
            <pubDate>Mon, 09 Sep 2019 03:34:11 GMT</pubDate>
            <atom:updated>2019-09-09T03:37:03.294Z</atom:updated>
            <content:encoded><![CDATA[<p>Python has many libraries to connect to SQL database like pyodbc, MYSQLdb, etc. In this tutorial, I will introduce sqlalchemy, a library that makes it easy to connect to SQL database in python. The syntax for this library is similar to pyodbc. We can follow a few simple steps to connect to our SQL database.</p><p><strong>Step 1: Importing libraries</strong></p><blockquote>import pyodbc<br>import sqlalchemy as sal<br>from sqlalchemy import create_engine<br>import pandas as pd</blockquote><p><strong>Step 2: Establishing connection to the database<br></strong># in order to connect, we need server name, database name we want to connect to</p><blockquote>engine = sal.create_engine(‘mssql+pyodbc://<strong>server_name</strong>/<strong>database_name</strong>?driver=SQL Server?Trusted_Connection=yes’)</blockquote><p>server_name : server you want to connect to<br>database_name : database you want to work with<br>Trusted_Connection = yes, when using windows authentication. If you have set a separate username and password for your SQL database, <br><strong>sal.create_engine(‘dialect+driver://username:password@host:port/database’)</strong></p><blockquote># establishing the connection to the databse using engine as an interface<br>conn = engine.connect()</blockquote><p>With this, we have established a connection to our SQL database. Now we can query our database for tables, updating those tables, creating new tables, etc.</p><p><strong>Step 3: Extracting table names present in the database</strong></p><blockquote># printing names of the tables present in the database<br>print(engine.table_names())</blockquote><p><strong>Step 4: Extracting table contents</strong></p><blockquote># checking whether the connection was actually established by selecting and displaying contents of table from the database<br>result = engine.execute(“select * from <strong>tablename</strong>”)<br>for row in result:<br> print (row)<br>result.close()</blockquote><p><strong>We can save our table as a pandas data frame. Another way is to query the database table into a data frame directly.</strong></p><p><strong>Reading and saving table to a pandas data frame</strong></p><blockquote># reading a SQL query using pandas<br>sql_query = pd.read_sql_query(‘SELECT * FROM <strong>database_name.dbo.tablename</strong>’, engine)</blockquote><blockquote># saving SQL table in a pandas data frame<br>df = pd.DataFrame(sql_query, columns = [‘column1’,‘column2’,…..])</blockquote><blockquote># printing the dataframe<br>df</blockquote><p><strong>Reading an external file and storing it to a SQL table</strong></p><p>We can read a CSV, excel file and store its content to a SQL table.</p><blockquote>df = pd.read_csv(‘<strong>tablename</strong>’)<br># create a new table and append data frame values to this table<br>df.to_sql(‘tablename’, con=engine, if_exists=’append’,index=False,chunksize=1000)</blockquote><p><strong>Closing the connection</strong></p><blockquote>conn.close()</blockquote><p>This is a simple and basic approach to establish a connection to the database and append values to the tables.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2be2cf883f85" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>