<?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 Jay Dholakia on Medium]]></title>
        <description><![CDATA[Stories by Jay Dholakia on Medium]]></description>
        <link>https://medium.com/@JayDholakia21?source=rss-174ec7776d42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fbrX34Py2OrUIwLyLRL05w.jpeg</url>
            <title>Stories by Jay Dholakia on Medium</title>
            <link>https://medium.com/@JayDholakia21?source=rss-174ec7776d42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:13:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JayDholakia21/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[How do I insert data into MongoDB using Python.]]></title>
            <link>https://levelup.gitconnected.com/how-do-i-insert-data-into-mongodb-using-python-16a263bb30b4?source=rss-174ec7776d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/16a263bb30b4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[programming-tips]]></category>
            <dc:creator><![CDATA[Jay Dholakia]]></dc:creator>
            <pubDate>Wed, 14 Feb 2024 03:13:24 GMT</pubDate>
            <atom:updated>2024-02-14T03:13:24.717Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Insertion into MongoDB Using Python.</h4><p>I am thrilled to guide you through the seamless process of inserting data into MongoDB using the power of Python. 🐍🔍</p><p>Below there is step-by-step tutorial with helpful insights, I’ve curated delightful blog to help you master the art of data insertion. Whether you’re a beginner eager to learn or an enthusiast looking to enhance your skills, I am here to make your journey enjoyable and enlightening.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1c6GoM_rb4es4PdO.png" /></figure><p>MongoDB, data insertion is a fundamental operation that involves adding documents (which are equivalent to rows in a table) to a collection (which is equivalent to a table). The provided code snippet uses the pymongo library to insert data from a CSV file into a MongoDB collection. Let&#39;s break down the key aspects of data insertion in MongoDB based on the code:</p><ol><li>Connecting to MongoDB: The first step is to establish a connection to your MongoDB server using the MongoClient class. This client object acts as your gateway to interact with the database.</li></ol><p><em>PyMongo</em> is the official MongoDB driver for Python, which allows you to interact with MongoDB databases using Python code. It provides a convenient and powerful interface to perform various operations such as data insertion, retrieval, update, and deletion within MongoDB collections. Here’s some information about the key features and components of the PyMongo module:</p><p>a. Installation: You can install PyMongo using the following command:</p><pre>pip install pymongo</pre><p>b. Import the Module:</p><pre>from pymongo import MongoClient</pre><p>2. Selecting a Database: You need to select or create a database within the MongoDB server where you want to store your data. In the code, this is done using client[&#39;your_database_name&#39;], where &#39;your_database_name&#39; should be replaced with the desired database name.</p><p>3. Creating or Selecting a Collection: A collection is where you’ll store your data documents. In the code, the collection is created or selected using db[collection_name], where collection_name should be replaced with your desired collection name.</p><p>4. Reading Data from CSV: The CSV file data is read into a pandas DataFrame using pd.read_csv(csv_file_path).</p><p>5. Transforming Data: The DataFrame is converted into a list of dictionaries using df.to_dict(orient=&#39;records&#39;). Each dictionary represents a row of data, and the list of dictionaries corresponds to the data you want to insert into the MongoDB collection.</p><p>6. Inserting Data: The data is inserted into the MongoDB collection using collection.insert_many(data). This method takes the list of dictionaries (data) and adds each dictionary as a separate document in the collection.</p><p><strong>Note:</strong></p><p>a. MongoDB’s insert_many() method is designed to add new documents to the collection without overwriting existing data.</p><p>b. Each time you call the collection.insert_many(data) method, it will insert the new data provided in the data variable into the collection, keeping the existing data intact.</p><p>7. Closing the Connection: After the data is inserted, it’s a good practice to close the MongoDB connection using client.close().</p><p>8. Remember that MongoDB is a NoSQL database, and it doesn’t enforce a fixed schema for collections. Each document can have different fields. In the context of your code, the structure of each document is determined by the columns in your CSV file.</p><pre>import pandas as pd<br>from pymongo import MongoClient<br><br>def import_csv_to_mongodb(csv_file_path, database_name, collection_name):<br>    try:<br>        # Read CSV data into a pandas DataFrame<br>        df = pd.read_csv(csv_file_path)<br><br>        # Convert the DataFrame to a list of dictionaries (each row becomes a dictionary)<br>        data = df.to_dict(orient=&#39;records&#39;)<br><br>        # Connect to MongoDB<br>        client = MongoClient(&#39;localhost&#39;, 27017)<br>        db = client[database_name]<br>        collection = db[collection_name]<br><br>        # Insert the data into your collection<br>        collection.insert_many(data)<br><br>        # Close the MongoDB connection<br>        client.close()<br><br>        print(&quot;Data imported successfully into MongoDB.&quot;)<br><br>    except Exception as e:<br>        print(f&quot;Error occurred: {e}&quot;)<br><br># Input Example <br>csv_file_path = &#39;path/to/your/csv_file.csv&#39;<br>database_name = &#39;your_database_name&#39;<br>collection_name = &#39;your_collection_name&#39;<br><br>import_csv_to_mongodb(csv_file_path, database_name, collection_name)</pre><p>With this code, each time you run it, the new dataset from the CSV file will be added as documents to the specified collection in the MongoDB database. This allows you to accumulate data over time, as each new dataset appends to the existing collection</p><p>If your data is not getting stored into the database, there could be a few possible reasons for this issue:</p><ol><li>Connection Issue: Double-check that your MongoDB server is running, and you are connecting to the correct host and port using the MongoClient.</li><li>Database and Collection Existence: Ensure that the specified database and collection exist. If they don’t exist, you can use db.create_collection(collection_name) to create the collection dynamically.</li><li>Document Format: Verify that the data you are trying to insert into the collection is in the correct format. Each document should be a Python dictionary representing a row of data from your CSV file.</li><li>Data Transformation: Check if there are any issues with the data transformation (from DataFrame to dictionary) or data cleaning steps that might affect the insertion process.</li><li>Exception Handling: Wrap the insertion code in a try-except block to catch any errors during the insertion process and print or log the error message.</li></ol><p>I hope this blog has helped you learn something new! If yes, then let’s connect, learn, and grow together. Follow me for more such blogs and share it with friends/colleagues for collaborative learning.</p><p>Get ready to unlock the potential of MongoDB’s and Python’s capabilities and create a lasting impact with your projects. Join me on this exciting adventure.</p><p>Happy learning and happy inserting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a263bb30b4" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-do-i-insert-data-into-mongodb-using-python-16a263bb30b4">How do I insert data into MongoDB using Python.</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to connect Python with MongoDB.]]></title>
            <link>https://levelup.gitconnected.com/how-to-connect-python-with-mongodb-350ebcc94efd?source=rss-174ec7776d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/350ebcc94efd</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[database-administration]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Jay Dholakia]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 12:55:46 GMT</pubDate>
            <atom:updated>2023-07-07T12:55:46.295Z</atom:updated>
            <content:encoded><![CDATA[<h4>Python and MongoDB Unite: A Step-by-Step Guide to Connecting and Interacting with MongoDB</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DayRvxy6KpTd1K0_.jpg" /></figure><p>To connect MongoDB with Python, you can use the PyMongo library, which is the official Python driver for MongoDB. Here’s a step-by-step guide on how to connect MongoDB with Python.</p><p><strong>Step 1: Installing Required Library.</strong></p><p>Firstly, you will need to install pymongo module on our environment. If you are installing it on VS Code, then run the below driver code on your terminal.</p><p><strong><em>pip install pymongo</em></strong></p><p>If you want it on your anaconda environment, then run the below python driver.</p><p><strong><em>conda install -c anaconda pymongo</em></strong></p><p><strong>Step 2: Import Required Module.</strong></p><p>After completing the above step, import the required module in your code.</p><pre>from pymongo import MongoClient</pre><p><strong>Step 3: Connect to the MongoDB server.</strong></p><p>If MongoDB is running on the localhost with default port 27017, write the below code to connect python with the MongoDB Server.</p><pre><br>client = MongoClient()</pre><p>If MongoDB is running on a specific host and port, use the below code to connect and ignore the above example.</p><pre>from pymongo import MongoClient<br><br># Provide the connection details<br>hostname = &#39;your_host_name&#39;<br>port = 27017  # Default MongoDB port<br>username = &#39;your_username&#39;  # If authentication is required<br>password = &#39;your_password&#39;  # If authentication is required<br><br># Create a MongoClient instance<br>client = MongoClient(hostname, port, username=username, password=password)</pre><p><strong>Step 4: Access a specific database.</strong></p><p>If you want to access some data from a database then refer the below code to access your database which is already created in MongoDB.</p><pre>db = client[&#39;your_database_name&#39;]</pre><p><strong>Step 5: Access a specific Collection (i.e Table).</strong></p><p>After accessing the database, inorder to access the collection (i.e table) created in your database from which you want to access specific data, refer the example below to connect with particular collection.</p><pre># Access a collection (similar to a table in relational databases)<br>collection = db[&#39;your_collection_name&#39;]</pre><p><strong>Step 6: Close Connection</strong></p><p>Use the code below to close the MongoDB connection when you’re done.</p><pre>client.close()</pre><p>This was a basic example to get you started with connecting MongoDB. I hope this blog has helped you learn something new! If yes, then let’s connect, learn, and grow together. Follow me for more such blogs and share it with friends/colleagues for collaborative learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=350ebcc94efd" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-to-connect-python-with-mongodb-350ebcc94efd">How to connect Python with MongoDB.</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB vs SQL]]></title>
            <link>https://python.plainenglish.io/mongodb-vs-sql-309d8ae5ad7d?source=rss-174ec7776d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/309d8ae5ad7d</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mongodb-compass]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[database-development]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Jay Dholakia]]></dc:creator>
            <pubDate>Thu, 06 Jul 2023 08:16:40 GMT</pubDate>
            <atom:updated>2023-07-06T08:16:40.248Z</atom:updated>
            <content:encoded><![CDATA[<h4>Comparing Database Powerhouses</h4><p><em>what is MongoDB ?</em></p><p>It is a popular open-source NoSQL (non-relational) database management system which is designed to handle large volumes of data and provide high performance, scalability, and flexibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hpdM-3D1YgkLROV_ZLrJAQ.png" /></figure><p><em>Let’s get into the battle⚔️ of MongoDB vs SQL.</em></p><p>To get into more detail about mongodb, understanding the difference between them is the most important part to get a clear idea.</p><p>MongoDB is a NoSQL database, which means it has a different structure and approach compared to traditional SQL databases.</p><ul><li>SQL databases use a <strong><em>structured data model</em></strong> based on tables with predefined schemas. Whereas, MongoDB uses a flexible and schema-less data model known as a <strong><em>document-oriented model</em></strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CfkOba1TP5SJEH-vor5KsQ.jpeg" /><figcaption>Image showcasing MongoDB data model.</figcaption></figure><ul><li>Each table in Sql consists of rows (records) and columns (fields) where data is stored. Here in Mongodb, data is stored in flexible documents(containing information about rows) within collections(i.e tables). Each document can have a different structure, and fields(i.e colums) can be added or modified without requiring a predefined schema.</li><li>SQL databases use the structured query language (SQL) for querying and manipulating data. SQL provides a standardized syntax for performing operations such as SELECT, INSERT, UPDATE, and DELETE. Whereas, MongoDB uses its own query language called the MongoDB Query Language (MQL). It is designed to work with the document-based data model of MongoDB and supports a wide range of query operators (Comparison, Logical, Element, Array, etc).</li><li>SQL databases typically scale vertically, increasing the hardware resources (CPU, memory, storage) of a single server. But, MongoDB is designed for horizontal scalability, allowing us to distribute data across multiple servers to handle large amount of data and high traffic loads.</li></ul><p><em>So, let me introduce you’ll to the interface used for MongoDB?</em></p><p>MongoDB Compass is a visual GUI (Graphical User Interface) tool provided by MongoDB for interacting with MongoDB databases. It offers a user-friendly interface that allows us to explore, query, and manipulate data in MongoDB.</p><p>With MongoDB Compass, we can perform various tasks such as:</p><ol><li><strong>Connect to a MongoDB server:</strong> Compass allows us to connect to a MongoDB server by providing the server’s connection details.</li><li><strong>Explore databases and collections:</strong> Once connected, we can navigate through databases and collections in MongoDB server.</li><li><strong>View and edit documents:</strong> Compass provides a document view that allows us to see the documents in a collection in a structured format. We can also edit the documents directly within Compass.</li><li><strong>Run queries:</strong> Compass allows us to write and execute queries using a visual query builder or the MongoDB Query Language (MQL).</li></ol><p>If you to know more about Mongodb Compass you can visit the link below, and can download it as per your device requirements.</p><p><a href="https://www.mongodb.com/products/compass">MongoDB Compass</a></p><p>I hope this blog has helped you learn something new! If yes, then let’s connect, learn, and grow together. Follow me for more such blogs and share it with friends/colleagues for collaborative learning.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=309d8ae5ad7d" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/mongodb-vs-sql-309d8ae5ad7d">MongoDB vs SQL</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debug Like a Pro | Demystifying Debugging]]></title>
            <link>https://levelup.gitconnected.com/debug-like-a-pro-demystifying-debugging-beaa668da0c4?source=rss-174ec7776d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/beaa668da0c4</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Jay Dholakia]]></dc:creator>
            <pubDate>Wed, 28 Jun 2023 04:48:51 GMT</pubDate>
            <atom:updated>2023-06-28T04:48:51.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*PERmaQNVy_BAzu27grRLbA.png" /><figcaption>Illustration showcasing Debugging.</figcaption></figure><p>Debugging is an essential process in software development and programming. It involves identifying and resolving issues, errors, and unexpected behavior in code. Here are some key reasons why debugging is necessary.</p><ol><li>Finding and fixing errors.</li><li>Verifying program logic.</li><li>Understanding program behavior.</li><li>Optimizing performance.</li><li>Testing and quality assurance.</li><li>Learning and skill development.</li></ol><p>After extensive research on various websites and videos, I discovered a lack of comprehensive resources for learning how to effectively debug code. Realizing the value of my own experience and knowledge in this area, I decided to create a blog. Through this blog, I aim to provide valuable insights and practical guidance on debugging, helping readers expand their understanding and proficiency in this essential skill.</p><p>During our college days, we were introduced to the concepts of debugging, but we rarely had the opportunity to apply it practically or gain hands-on experience. Recognizing the importance of bridging this gap, I have created a comprehensive step-by-step guide on debugging. This guide will walk you through the process, providing practical examples and insights, allowing you to develop a strong foundation in debugging techniques.</p><ol><li><strong>Start Debugging</strong></li></ol><p>In spyder there is debug option in the toolbar. To run your code in debug mode, you have a couple of options. You can either click on the green play button with a bug icon in the toolbar, or you can use the Ctrl+F5 keyboard shortcut. This will start your code execution with the debugger enabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*5skzu6MFBboQcuiHD_2_Jg.jpeg" /><figcaption>Image showcasing how to start debug mode.</figcaption></figure><p>2. <strong>Adding</strong> <strong>Breakpoints</strong></p><p>In Spyder, you can set breakpoints at specific lines in your code where you want the debugger to pause execution. To set a breakpoint, simply click on the line number in the editor window or press F12 on your keyboard. You can press the same to clear breakpoints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*ogUDmroxrc7fUOKmqYM5PQ.png" /><figcaption>Image showcasing breakpoint added at line 12.</figcaption></figure><p>3. <strong>Stepping Into</strong></p><p>It allows you to dive deeper into the code and explore the execution flow within functions. By selecting “step into” (often denoted as Ctrl+F11) will enter the function call.</p><p>Tip: Place the breakpoint at the function call and then step into to closely analyze its inner workings, inspect values of the variables.</p><p>Refer below process for stepping into.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6r66ltH3lzl_Wwkx9A92vQ.png" /><figcaption>Image showcasing the breakpoint set at function call square_number(9) line 12.</figcaption></figure><p>Now if I execute “step into” command, the arrow directs to the function and steps into it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkY6oWTbdlFFgkpedlRSCQ.png" /><figcaption>Image showcasing &quot;step into&quot; execution at line 2.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bPyWL_KXYVJg3p0SdXlrXg.png" /><figcaption>Image showcasing &quot;step into&quot; execution at line 3.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-IUlreD7zJwh7wuJuXFi-g.png" /><figcaption>Image showcasing &quot;step into&quot; execution at line 4.</figcaption></figure><p><strong>3. Stepping/Stepping Over</strong></p><p>When you use “step,” the debugger will execute the entire line as a single step, regardless of whether there are any function calls on that line.</p><p>If there is a function call on the current line, the “step”/”step over” command will execute the entire function call without diving into the details of the called function. It will simply move to the next line after the function call.</p><p>4. <strong>Return</strong></p><p>After processing through each and every line it returns back to the the function call and shows the return message at the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dwI2nd6JOlCkJoQkWuGPFg.png" /><figcaption>Image showcasing execution of &quot;return&quot; command.</figcaption></figure><p>5.<strong> Continue</strong></p><p>It resumes the execution of a program from the current point, allowing it to run until the next breakpoint or the end of the program.</p><p>You can observe image below how after pressing “continue” command the arrow directly comes to line 6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*baISiur8ok7EKeGtnJbLaA.png" /><figcaption>Image showcasing process of &quot;continue&quot; command.</figcaption></figure><p>Now if I set breakpoint to line 4 after executing continue statement the arrow from line 6 now processes the code and stops at line 4 without any hault in-between.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McAbsMO_YuIfLzgzhKhDyw.png" /><figcaption>Image showcasing process of &quot;continue&quot; command.</figcaption></figure><p>I hope this blog has helped you clear your doubts and learn something new! If yes, then let’s connect, learn, and grow together, follow me for more such blogs and share it with friends/colleagues for collaborative learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beaa668da0c4" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/debug-like-a-pro-demystifying-debugging-beaa668da0c4">Debug Like a Pro | Demystifying Debugging</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to pad digits in python : Unexplored tips and tricks.]]></title>
            <link>https://python.plainenglish.io/how-to-pad-digits-in-python-unexplored-tips-and-tricks-8ec607a44eb4?source=rss-174ec7776d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ec607a44eb4</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Jay Dholakia]]></dc:creator>
            <pubDate>Mon, 26 Jun 2023 12:16:49 GMT</pubDate>
            <atom:updated>2023-06-26T12:16:49.260Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Pad Digits in Python: Unexplored Tips and Tricks</h3><p><strong><em>What is formatting and is there any need for it?</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*mi_u6uDRY1uqpr7d8qNs7w.png" /><figcaption>Illustration showcasing formatting</figcaption></figure><p>Formatting means to arrange something, such as material to be printed or stored data in a particular format.</p><p><strong><em>format()</em> </strong>is the name of the method which helps to format the specified value, this method returns the formatted string and insert them inside the string&#39;s placeholder.</p><p><strong><em>What are Placeholder ?</em></strong></p><p>The placeholder is defined using curly brackets <strong><em>{}</em></strong>.</p><p>The placeholders can be identified using named indexes {variable}, numbered indexes {0}, or even empty placeholders {}.</p><pre>#named indexes {variable}<br>txt1 = &quot;My name is {variable1}, I&#39;m {variable2}&quot;.format(variable1 = value1, variable2 = value2) <br>#numbered indexes {0}<br>txt2 = &quot;My name is {0}, I&#39;m {1}&quot;.format(value1, value2)<br>#empty placeholders {}<br>txt3 = &quot;My name is {}, I&#39;m {}&quot;.format(value1, value2)<br><br>print(txt1)<br>print(txt2)<br>print(txt3)<br><br>#Output <br>&quot;&quot;&quot;<br>My name is value1, I&#39;m value2<br>My name is value1 , I&#39;m value2<br>My name is value1, I&#39;m value2<br>&quot;&quot;&quot;</pre><p><strong>note:</strong><em> value1, value2 can be string or integer.</em></p><p>I hope above examples may have helped you understand above formatting. All txt1, txt2, txt3 are doing the same thing but there are multiple ways to write the syntax.</p><p>This was just about normal formatting but suppose if ask you to convert single digits numbers into double digits</p><p>example:</p><p>5 → 05</p><p>So, what logic should be written in addition to this format method so that the task can be done within the single line of code and make our work easy.</p><p>Check example below:</p><pre>--&gt; {}.format(1, &#39;02&#39;)<br>&#39;01&#39;<br><br>--&gt; {}.format(100, &#39;02&#39;)<br>&#39;100&#39;<br>        <br>--&gt; &#39;{:02}&#39;.format(1)<br>&#39;01&#39;<br><br>--&gt; &#39;{:02}&#39;.format(100)<br>&#39;100&#39;</pre><p>All the above 4 examples are doing the same thing but the syntax of writing it is different.</p><p>Explanation of these example above:</p><p>First 2 examples are converting the input integer 1 into 2 digit by padding zero before 1 and making it a 2-digit and returning it in the form of string and passing it to placeholder and get ‘01’ as output. Same way logic works for second example, but the digit here itself is in 3-digit format so no padding is done to it.</p><p>Similarly, next 2 examples do the same thing which I have explained here above but syntax of writing it is different.</p><p>Now, suppose for real life scenario where I want the data for date in 2-digit format.</p><p>eg. <br>hr:min:sec → 1) 9:15:20 → <strong>0</strong>9:15:20 2) 10:5:8 → 10:<strong>0</strong>5:<strong>0</strong>8</p><p>So, the code is,</p><pre>&#39;{:02}&#39;.format(hr) + &#39;{:02}&#39;.format(min) + &#39;{:02}&#39;.format(sec)</pre><p>The above code will convert hr, min, sec into 2-digit, if you think what happens to digits which are already in 2 digit format so, it takes care of the 2-digits by keeping it as it is and converting single digit into double digits format.</p><p>You must have observed how single line of code made our work easy and efficient.</p><p>I hope this blog has helped you clear your doubts! and helped you learn something new. If yes, let’s connect, learn, and grow together, follow me for more such blogs and share it with friends/colleagues for collaborative learning.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ec607a44eb4" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/how-to-pad-digits-in-python-unexplored-tips-and-tricks-8ec607a44eb4">How to pad digits in python : Unexplored tips and tricks.</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unveiling the power of Window function to ace SQL.]]></title>
            <link>https://levelup.gitconnected.com/unveiling-the-power-of-window-function-to-ace-sql-29faaddd8431?source=rss-174ec7776d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/29faaddd8431</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[sql-window-functions]]></category>
            <dc:creator><![CDATA[Jay Dholakia]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 13:25:58 GMT</pubDate>
            <atom:updated>2023-06-01T13:25:58.492Z</atom:updated>
            <content:encoded><![CDATA[<p>For those who don’t know what window function is and how it works, let’s understand it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*lP_HPgVm7zbDya9qUpcX9Q.png" /><figcaption>Illustration showcasing the working of a window function on our dataset.</figcaption></figure><p>Window function applies aggregate like sum(), avg(), count() and ranking functions rank(), dense_rank(), row_number() over a particular window i.e <strong><em>set of rows</em> </strong>it is followed by OVER clause.</p><p><strong>OVER</strong> clause is used with window functions to define that window. It does following things:</p><ul><li>partitioning rows into set of rows with the help of PARTITION BY clause</li><li>ordering rows within those partitions using ORDER BY clause, so that it can be ordered into ascending/descending order.</li></ul><p>Now, let’s understand how to use and write the window function.</p><p><strong><em>Input: Queries table</em></strong></p><pre>Input: <br>Queries table:<br>+------------+-------------------+----------+--------+<br>| query_name | result            | position | rating |<br>+------------+-------------------+----------+--------+<br>| Dog        | Golden Retriever  | 1        | 5      |<br>| Dog        | German Shepherd   | 2        | 5      |<br>| Dog        | Mule              | 200      | 1      |<br>| Cat        | Shirazi           | 5        | 2      |<br>| Cat        | Siamese           | 3        | 3      |<br>| Cat        | Sphynx            | 7        | 4      |<br>+------------+-------------------+----------+--------+</pre><p>Suppose, I have to get the average of the ratio between rating and its position such that the output should look like</p><p><strong><em>Output:</em></strong> <strong><em>query_name and quality(newly calculated) from Queries table.</em></strong></p><pre>Output:<br>+------------+---------+<br>| query_name | quality |<br>+------------+---------+<br>| Dog        | 2.50    | <br>| Cat        | 0.66    |     <br>+------------+---------+</pre><p>Now, let’s explore how the window function will simplify our task.</p><p><strong><em>Code:</em></strong></p><pre>select distinct query_name, avg(rating / position) over (partition by query_name) as quality <br>from Queries</pre><p>You can observe how window functions helped it condense into a concise line of code, thereby enhancing its efficiency.</p><p>Also note Window functions are classified into 3 types:</p><ol><li><strong>Aggregate Window function.</strong></li><li><strong>Ranking Window functions .</strong></li><li><strong>Value Window functions.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*-bTBnv_kLD8I8MUxj7fosA.png" /><figcaption>Image showing in-detail classification of window functions.</figcaption></figure><p>That’s all, this blog was just about how window function works, but if you want to understand more in-depth about the types of window functions that are used and also the sub-types mentioned above in detail, then follow me to get more of such content.</p><p>If you want to practice window function for self-learning or for interview preparation then solve this problem statement from Leetcode by clicking this link below.</p><p><a href="https://leetcode.com/problems/queries-quality-and-percentage/?envType=study-plan-v2&amp;envId=top-sql-50">Queries Quality and Percentage - LeetCode</a></p><p>If you want the solution of the same, refer this video linked below. I have explained it in-detail.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F77VfbM1pVxY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D77VfbM1pVxY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F77VfbM1pVxY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f7be896d1af1681b1e98ce5a597c211/href">https://medium.com/media/7f7be896d1af1681b1e98ce5a597c211/href</a></iframe><p>I hope this blog has helped you to clear your doubts! If yes, let’s connect, learn, and grow together, follow me for more such blogs and share it with friends/colleagues for collaborative learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29faaddd8431" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/unveiling-the-power-of-window-function-to-ace-sql-29faaddd8431">Unveiling the power of Window function to ace SQL.</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding When and How to Use “Where” and “Having” properly.]]></title>
            <link>https://levelup.gitconnected.com/understanding-when-and-how-to-use-where-and-having-properly-aa1f5f0c5b70?source=rss-174ec7776d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa1f5f0c5b70</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Jay Dholakia]]></dc:creator>
            <pubDate>Tue, 30 May 2023 12:25:28 GMT</pubDate>
            <atom:updated>2023-05-30T12:25:28.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*dYlBMGpxTEHMqDrUJbgwtg.jpeg" /><figcaption>Source: Dribble</figcaption></figure><p>Many of us have observed that while studying sql keywords like “where” and “having” individually it must have gotten into head easily without any doubt but when we start writing queries and when these two keywords to be used together it creates confusion. If you got confused don’t worry I also had the same situation but as you can see now I have mastered it and written the blog on the same. Don’t worry the concepts gets clear with practice ;)</p><p>The SQL <strong>WHERE</strong> clause is used to filter records while retrieving the data from a single table or multiple tables (after join operation). It helps to specify a condition while fetching the data and if this condition is satisfied, then it returns filtered data from the table.</p><p>You can refer the example how “where” statement is written to get the candidates that have years of experience greater than or equal to 2 in the query below.</p><pre>select c.candidate_id<br>from Candidates c<br>inner join Rounds r on c.interview_id = r.interview_id<br>where c.years_of_exp &gt;= 2</pre><p>The SQL<strong> </strong>HAVING clause is similar to the WHERE clause, they are both used to filter rows in a table based on conditions.</p><p>However, the <strong>HAVING</strong> clause is used to filter <strong><em>grouped</em></strong> rows instead of single rows. These rows are grouped together by the GROUP BY clause, so, the “having” must always be followed by the “group by”.</p><p>See how “having” keyword is used after “group by” to get the sum of the score greater than 15. It is used with <strong><em>aggregate functions </em></strong>mostly..</p><pre>select c.candidate_id<br>from Candidates c<br>inner join Rounds r on c.interview_id = r.interview_id<br>where c.years_of_exp &gt;= 2<br>group by r.interview_id<br>having sum(r.score) &gt; 15</pre><p>Examples of aggregate functions are COUNT(), AVG(), SUM(). To understand about these functions into detail refer link below.</p><p><a href="https://www.w3schools.com/sql/sql_count_avg_sum.asp">SQL COUNT(), AVG() and SUM() Functions</a></p><p>I hope this blog has helped you to clear your doubts! If yes, let’s connect, learn, and grow together, follow me for more such blogs and share it with friends/colleagues for collaborative learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa1f5f0c5b70" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/understanding-when-and-how-to-use-where-and-having-properly-aa1f5f0c5b70">Understanding When and How to Use “Where” and “Having” properly.</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>