<?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"><channel><title><![CDATA[Anjaan Gaire's Blog]]></title><description><![CDATA[Anjaan Gaire's Blog]]></description><link>https://blog.sagargaire.com.np</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1667454492135/664knObmA.png</url><title>Anjaan Gaire&apos;s Blog</title><link>https://blog.sagargaire.com.np</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 12:39:03 GMT</lastBuildDate><atom:link href="https://blog.sagargaire.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Host your React app to Vercel]]></title><description><![CDATA[React.js, commonly referred to as React, is an open-source, powerful front-end javascript library. It is used to build beautiful user interfaces by combining multiple components of code into fully functional websites. We can build whole sites with Re...]]></description><link>https://blog.sagargaire.com.np/host-your-react-app-to-vercel</link><guid isPermaLink="true">https://blog.sagargaire.com.np/host-your-react-app-to-vercel</guid><category><![CDATA[2Articles1Week]]></category><category><![CDATA[React]]></category><category><![CDATA[hosting]]></category><category><![CDATA[hosting webpage]]></category><category><![CDATA[buildingandlearning]]></category><dc:creator><![CDATA[Sagar Gaire]]></dc:creator><pubDate>Sun, 14 May 2023 17:05:51 GMT</pubDate><content:encoded><![CDATA[<p>React.js, commonly referred to as React, is an open-source, powerful front-end javascript library. It is used to build beautiful user interfaces by combining multiple components of code into fully functional websites. We can build whole sites with React or use something minimal for just a page in a site.</p>
<p>React is created by merging JavaScript with XML, often known as JSX. While the learning curve for React is severe for a junior developer, it is one of the most popular and in-demand javascript libraries for front-end development.</p>
<p>Getting started with React is as easy as it can get. You just have to have Node.js installed locally. In your terminal type</p>
<pre><code class="lang-bash">npx create-react-app
</code></pre>
<p>Or if you are in a hurry, you can try <a target="_blank" href="https://vitejs.dev/">Vite</a>. It is fast and easy to set up any javascript project.</p>
<p>I'll not build an entire app from scratch but will use an existing one for this blog.</p>
<p>I have a project ready with Vite and React js. I've set up a GitHub repo for the project and will deploy the app from GitHub to Vercel.</p>
<p>First, go to https://vercel.com and register for free. You'll then be redirected to your dashboard where you can add your projects.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684082064671/0647e87d-095c-4fa6-81a8-9c2e5ecb4875.png" alt class="image--center mx-auto" /></p>
<p>Click on the Project on the dropdown and you'll be redirected to the import section.</p>
<p>Use the search bar if your repository is not shown by default and the matching repos will be listed here.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684082564425/77d89ee0-4c9f-472b-b454-0536796a69c9.png" alt class="image--center mx-auto" /></p>
<p>Click on the Import button. You'll now see the configuration for your project. I'll use the default config, you can change anything here.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684082653592/077f2171-1a6a-4045-b253-5cf6f24100fe.png" alt class="image--center mx-auto" /></p>
<p>You can override the build commands, output directory, install commands and add environment variables if you want.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684082715914/c1b34366-f12a-46cd-a77d-f67f536e1c7a.png" alt class="image--center mx-auto" /></p>
<p>Now click on the Deploy button at the bottom of the screen.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684082755947/7f8d4834-0789-4f89-a380-2bf8a1e16ca0.png" alt class="image--center mx-auto" /></p>
<p>Your deployment should finish almost instantly for small projects, but it may take longer for larger applications.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684082827344/cf4c1960-6262-4208-9ae2-4f72e34fd66d.png" alt class="image--center mx-auto" /></p>
<p>Congratulations you just deployed a new project to Vercel!</p>
<p>If you now continue to the dashboard you'll see your production build listed there. Click on the project you just deployed and you'll see the production deployment of your product.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684082982348/9417e6ba-09f5-4d1c-b5f5-7988683db1d6.png" alt class="image--center mx-auto" /></p>
<p>If you click on Visit at the top of your page, you'll be redirected to your site.</p>
<p>My site is now live :</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684083047091/c51818e8-05be-4868-a7d0-a42880634441.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-common-bugs-and-fixes">Common bugs and fixes</h3>
<ol>
<li><p>Environment Variables</p>
<p> If your project uses environment variables, and you fail to add them while building your project, your project may fall back to some error response rather than your site.</p>
<p> This can be easily fixed by adding environment variables to your project. Go to your project settings in Vercel and go to Environment Variables. Add your variables from here, or copy your <code>.env</code> directly.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684083232200/a6d3cd9f-6db0-4a3d-8d2d-3952115aa5d4.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Routes</p>
<p> Sometimes when deploying react app, your page shows a 404 error even if you have set up your routes correctly. This can be fixed easily with a few lines of code.</p>
<p> Go to your project root and create a file called <code>vercel.json</code> and add the following code there.</p>
<pre><code class="lang-json"> { <span class="hljs-attr">"routes"</span>: [{ <span class="hljs-attr">"src"</span>: <span class="hljs-string">"/[^.]+"</span>, <span class="hljs-attr">"dest"</span>: <span class="hljs-string">"/"</span>, <span class="hljs-attr">"status"</span>: <span class="hljs-number">200</span> }] }
</code></pre>
</li>
</ol>
<h3 id="heading-conclusion">Conclusion:</h3>
<p>You'll now be able to host your projects to Vercel without any issues. You can also host other projects with Vercel using their built-in templates that make it easy to deploy projects faster.</p>
<p>Thanks for reading the blog, if you have any questions, I'll be happy to answer them as far as I can.</p>
<p>If you like the content I'm posting, you can support me here: <a target="_blank" href="https://www.buymeacoffee.com/anjaangaire">https://www.buymeacoffee.com/anjaangaire</a> .</p>
]]></content:encoded></item><item><title><![CDATA[Data Analysis with Python: NumPy, Pandas and Matplotlib (Basic)]]></title><description><![CDATA[Python is an incredibly versatile language, and one of its strengths is its ability to work with data. With various libraries available, Python makes it easy to manipulate, analyze, and visualize data in a way that is both intuitive and powerful.
The...]]></description><link>https://blog.sagargaire.com.np/data-analysis-with-python-numpy-pandas-and-matplotlib-basic</link><guid isPermaLink="true">https://blog.sagargaire.com.np/data-analysis-with-python-numpy-pandas-and-matplotlib-basic</guid><category><![CDATA[pandas]]></category><category><![CDATA[numpy]]></category><category><![CDATA[Matplotlib]]></category><category><![CDATA[data analysis]]></category><category><![CDATA[Data Science]]></category><dc:creator><![CDATA[Sagar Gaire]]></dc:creator><pubDate>Tue, 11 Apr 2023 15:49:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1681227729698/b1581498-4fbb-4188-bbda-393a1624d95b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Python is an incredibly versatile language, and one of its strengths is its ability to work with data. With various libraries available, Python makes it easy to manipulate, analyze, and visualize data in a way that is both intuitive and powerful.</p>
<p>The most popular libraries for data analysis in Python are NumPy, Pandas and Matplotlib. NumPy is a library for working with numerical data, while Pandas is built on top of NumPy and provides more advanced functionality for data manipulation and analysis and Matplotlib is used to plot the data in user-friendly charts and graphs. In this article, we’ll explore how to use these libraries to analyze data in Python.</p>
<h6 id="heading-ps-this-tutorial-assumes-that-you-have-a-basic-understanding-of-how-python-works-and-how-to-set-up-virtual-environments-to-separate-environments-for-different-projects"><strong><em>P.S.: This tutorial assumes that you have a basic understanding of how Python works and how to set up virtual environments to separate environments for different projects.</em></strong></h6>
<h3 id="heading-installing-numpy-and-pandas"><strong>Installing NumPy and Pandas</strong></h3>
<p>Before we can start analyzing data with NumPy, Pandas and Matplotlib, we need to install them, which is a simple process.</p>
<pre><code class="lang-python">pip install numpy pandas matplotlib
</code></pre>
<p>This will download and install NumPy, Pandas and Matplotlib on your system. With these packages installed, we're ready to start working with data.</p>
<h3 id="heading-numpy-basics"><strong>NumPy Basics</strong></h3>
<p>NumPy provides a powerful set of tools for working with numerical data in Python. One of the most important features of NumPy is the ndarray object, which provides a fast and efficient way to store and manipulate arrays of numerical data.</p>
<p>To get started with NumPy, we first need to import the library:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
</code></pre>
<p>This imports NumPy and renames it to "np" for our convenience. Creating an array in NumPy is simple. We can create a one-dimensional array (also called a vector) by passing a Python list to the np.array() function:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
x = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
print(x)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">[<span class="hljs-number">1</span> <span class="hljs-number">2</span> <span class="hljs-number">3</span>]
</code></pre>
<p>We can also create two-dimensional arrays (matrices) by passing a list of lists to the np.array() function:</p>
<pre><code class="lang-python">y = np.array([[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>], [<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]])
print(y)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">[[<span class="hljs-number">1</span> <span class="hljs-number">2</span> <span class="hljs-number">3</span>]
 [<span class="hljs-number">4</span> <span class="hljs-number">5</span> <span class="hljs-number">6</span>]]
</code></pre>
<p>NumPy provides a number of functions for creating arrays with specific values, such as zeros() and ones(). We can create an array of zeros with the np.zeros() and an array of ones with the np.ones() functions respectively:</p>
<pre><code class="lang-python">z = np.zeros((<span class="hljs-number">3</span>,<span class="hljs-number">3</span>))
print(z)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">[[<span class="hljs-number">0.</span> <span class="hljs-number">0.</span> <span class="hljs-number">0.</span>]
 [<span class="hljs-number">0.</span> <span class="hljs-number">0.</span> <span class="hljs-number">0.</span>]
 [<span class="hljs-number">0.</span> <span class="hljs-number">0.</span> <span class="hljs-number">0.</span>]]
</code></pre>
<pre><code class="lang-python">a = np.ones((<span class="hljs-number">4</span>,<span class="hljs-number">4</span>))
print(a)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">[[<span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span>]
 [<span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span>]
 [<span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span>]
 [<span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span> <span class="hljs-number">1.</span>]]
</code></pre>
<p>NumPy provides a lot of functions for manipulating arrays. For example, we can reshape an array with the reshape() function:</p>
<pre><code class="lang-python">a = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>])
b = a.reshape((<span class="hljs-number">2</span>,<span class="hljs-number">3</span>))
print(b)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">[[<span class="hljs-number">1</span> <span class="hljs-number">2</span> <span class="hljs-number">3</span>]
 [<span class="hljs-number">4</span> <span class="hljs-number">5</span> <span class="hljs-number">6</span>]]
</code></pre>
<p>We can also perform mathematical operations on arrays. For example, we can add two arrays together:</p>
<pre><code class="lang-python">c = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
d = np.array([<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>])
​
e = c + d
print(e)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">[<span class="hljs-number">5</span> <span class="hljs-number">7</span> <span class="hljs-number">9</span>]
</code></pre>
<p>Similarly, we can multiply two arrays together:</p>
<pre><code class="lang-python">f = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
g = np.array([<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>])
h = f * g
print(h)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">[ <span class="hljs-number">4</span> <span class="hljs-number">10</span> <span class="hljs-number">18</span>]
</code></pre>
<p>NumPy also provides functions for computing basic strategies on arrays. For example, we can compute the mean, median, and standard deviation of an array:</p>
<pre><code class="lang-python">i = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>])
print(np.mean(i))
print(np.median(i))
print(np.std(i))
</code></pre>
<p>Output:</p>
<pre><code class="lang-python"><span class="hljs-number">3.5</span>
<span class="hljs-number">3.5</span>
<span class="hljs-number">1.707825127659933</span>
</code></pre>
<h3 id="heading-pandas-basics"><strong>Pandas Basics</strong></h3>
<p>While NumPy provides a powerful set of tools for working with numerical data, it doesn't provide much in the way of data manipulation or analysis. This is where Pandas come in.</p>
<p>Pandas provides two main classes for working with data: Series and DataFrame. A Series is a one-dimensional array-like object, while a DataFrame is a two-dimensional table-like object. Both of these classes provide a rich set of functions for manipulating and analyzing data.</p>
<p>Creating a Series in Pandas is simple. We can create a Series from a Python list:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
s = pd.Series([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
print(s)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python"><span class="hljs-number">0</span>    <span class="hljs-number">1</span>
<span class="hljs-number">1</span>    <span class="hljs-number">2</span>
<span class="hljs-number">2</span>    <span class="hljs-number">3</span>
dtype: int64
</code></pre>
<p>The first column of the output shows the index of the Series, which is automatically generated by Pandas. We can also specify our own index:</p>
<pre><code class="lang-python">t = pd.Series([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>], index=[<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>])
print(t)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">a    <span class="hljs-number">1</span>
b    <span class="hljs-number">2</span>
c    <span class="hljs-number">3</span>
dtype: int64
</code></pre>
<p>Creating a DataFrame in Pandas is also simple. We can create a DataFrame from a Python dictionary:</p>
<pre><code class="lang-python">u = pd.DataFrame({<span class="hljs-string">'Name'</span>: [<span class="hljs-string">'Shady'</span>, <span class="hljs-string">'Tony'</span>, <span class="hljs-string">'Amanda'</span>], <span class="hljs-string">'Age'</span>: [<span class="hljs-number">25</span>, <span class="hljs-number">30</span>, <span class="hljs-number">35</span>]})
print(u)
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">     Name  Age
<span class="hljs-number">0</span>   Shady   <span class="hljs-number">25</span>
<span class="hljs-number">1</span>    Tony   <span class="hljs-number">30</span>
<span class="hljs-number">2</span>  Amanda   <span class="hljs-number">35</span>
</code></pre>
<p>Like Series, DataFrames also have an index, which is generated automatically if not specified.</p>
<p>Pandas provides a rich set of functions for manipulating and analyzing data. For example, we can filter a DataFrame to include only rows that meet a certain condition:</p>
<p>In [16]:</p>
<pre><code class="lang-cpp">v = pd.DataFrame({<span class="hljs-string">'Name'</span>: [<span class="hljs-string">'Shady'</span>, <span class="hljs-string">'Tony'</span>, <span class="hljs-string">'Amanda'</span>], <span class="hljs-string">'Age'</span>: [<span class="hljs-number">25</span>, <span class="hljs-number">30</span>, <span class="hljs-number">35</span>]})
w = v[v[<span class="hljs-string">'Age'</span>] &gt; <span class="hljs-number">30</span>]
print(w)
</code></pre>
<p>Output:</p>
<pre><code class="lang-cpp">     Name  Age
<span class="hljs-number">2</span>  Amanda   <span class="hljs-number">35</span>
</code></pre>
<p>We can also sort a DataFrame by a certain Column:</p>
<pre><code class="lang-cpp">x = pd.DataFrame({<span class="hljs-string">'Name'</span>: [<span class="hljs-string">'Shady'</span>, <span class="hljs-string">'Tony'</span>, <span class="hljs-string">'Amanda'</span>], <span class="hljs-string">'Age'</span>: [<span class="hljs-number">25</span>, <span class="hljs-number">30</span>, <span class="hljs-number">35</span>]})
y = x.sort_values(by=<span class="hljs-string">'Age'</span>)
print(y)
</code></pre>
<p>Output:</p>
<pre><code class="lang-cpp">     Name  Age
<span class="hljs-number">0</span>   Shady   <span class="hljs-number">25</span>
<span class="hljs-number">1</span>    Tony   <span class="hljs-number">30</span>
<span class="hljs-number">2</span>  Amanda   <span class="hljs-number">35</span>
</code></pre>
<p>Another useful function is groupby(), which allows us to group rows of a DataFrame by a certain column:</p>
<pre><code class="lang-cpp">z = pd.DataFrame({<span class="hljs-string">'Name'</span>: [<span class="hljs-string">'Alice'</span>, <span class="hljs-string">'Bob'</span>, <span class="hljs-string">'Charlie'</span>], <span class="hljs-string">'Gender'</span>: [<span class="hljs-string">'F'</span>, <span class="hljs-string">'M'</span>, <span class="hljs-string">'M'</span>], <span class="hljs-string">'Age'</span>: [<span class="hljs-number">25</span>, <span class="hljs-number">30</span>, <span class="hljs-number">35</span>]})
a = z.groupby(<span class="hljs-string">'Gender'</span>)[<span class="hljs-string">'Age'</span>].mean()
print(a)
</code></pre>
<p>Output:</p>
<pre><code class="lang-cpp">Gender
F    <span class="hljs-number">25.0</span>
M    <span class="hljs-number">32.5</span>
Name: Age, dtype: float64
</code></pre>
<p>This groups the rows of the DataFrame by the "Gender" column and computes the mean of the "Age" column for each group.</p>
<p>Now that we know some basic functionalities of NumPy and Pandas, let's move on to see how we can use these libraries for data analysis.</p>
<h3 id="heading-data-analysis-with-numpy-and-pandas"><strong>Data Analysis with NumPy and Pandas</strong></h3>
<p>Suppose we have a <a target="_blank" href="https://en.wikipedia.org/wiki/Comma-separated_values">CSV File</a>, containing some data we want to analyze. We can read the data into a pandas DataFrame using the read_csv() function:</p>
<pre><code class="lang-cpp">sales = pd.read_csv(<span class="hljs-string">'sales_data.csv'</span>)
sales.head(<span class="hljs-number">10</span>)
</code></pre>
<p>Output:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td></td><td><strong>id</strong></td><td><strong>store</strong></td><td><strong>product_group</strong></td><td><strong>product_code</strong></td><td><strong>stock_qty</strong></td><td><strong>cost</strong></td><td><strong>price</strong></td><td><strong>last_week_sales</strong></td><td><strong>last_month_sales</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>0</strong></td><td>100</td><td>Uler</td><td>PG3</td><td>4000</td><td>731</td><td>921.35</td><td>516.92</td><td>99</td><td>1412</td></tr>
<tr>
<td><strong>1</strong></td><td>101</td><td>Paladin</td><td>PG1</td><td>4001</td><td>80</td><td>984.39</td><td>436.05</td><td>12</td><td>1250</td></tr>
<tr>
<td><strong>2</strong></td><td>102</td><td>Uler</td><td>PG3</td><td>4002</td><td>2729</td><td>608.01</td><td>838.54</td><td>51</td><td>1970</td></tr>
<tr>
<td><strong>3</strong></td><td>103</td><td>Uler</td><td>PG2</td><td>4003</td><td>2217</td><td>577.97</td><td>62.61</td><td>1</td><td>1737</td></tr>
<tr>
<td><strong>4</strong></td><td>104</td><td>Paladin</td><td>PG1</td><td>4004</td><td>3652</td><td>633.66</td><td>1318.50</td><td>88</td><td>1727</td></tr>
<tr>
<td><strong>5</strong></td><td>105</td><td>Uler</td><td>PG3</td><td>4005</td><td>2183</td><td>254.73</td><td>1274.13</td><td>38</td><td>1264</td></tr>
<tr>
<td><strong>6</strong></td><td>106</td><td>Alpino</td><td>PG1</td><td>4006</td><td>3938</td><td>85.61</td><td>566.28</td><td>22</td><td>745</td></tr>
<tr>
<td><strong>7</strong></td><td>107</td><td>Uler</td><td>PG2</td><td>4007</td><td>2879</td><td>581.86</td><td>385.21</td><td>57</td><td>19</td></tr>
<tr>
<td><strong>8</strong></td><td>108</td><td>Alpino</td><td>PG1</td><td>4008</td><td>4943</td><td>287.91</td><td>952.56</td><td>25</td><td>1360</td></tr>
<tr>
<td><strong>9</strong></td><td>109</td><td>Paladin</td><td>PG1</td><td>4009</td><td>3273</td><td>786.10</td><td>754.78</td><td>100</td><td>1610</td></tr>
</tbody>
</table>
</div><p>This assumes that the CSV file is located in the same directory as our Python script. If the file is present somewhere else, we should give the exact path to that location. For example, 'home/user/my_project/data.csv'</p>
<p>Once we have the data in the DataFrame, we can use Pandas functions to analyze it. We have a CSV file that contains information about different stores' sales data including their product group, product code, stock quantity, cost, price, and sales. We can compute some statistics based on this data using Pandas.</p>
<pre><code class="lang-cpp">average_cost = sales[<span class="hljs-string">'cost'</span>].mean()
print(<span class="hljs-string">"Average Cost: "</span>, average_cost)

total_sales_week = sales.groupby(<span class="hljs-string">'store'</span>)[<span class="hljs-string">'last_week_sales'</span>].sum()
print(<span class="hljs-string">"Total sales last week: "</span>, total_sales_week)
</code></pre>
<p>Output:</p>
<pre><code class="lang-cpp">Average Cost:  <span class="hljs-number">502.79470000000003</span>
Total sales last week:  store
Alpino      <span class="hljs-number">915</span>
Mary       <span class="hljs-number">1024</span>
Paladin    <span class="hljs-number">1200</span>
Soner      <span class="hljs-number">1066</span>
Uler       <span class="hljs-number">1222</span>
Name: last_week_sales, dtype: int64
</code></pre>
<p>We can also filter the data based on certain conditions. For example, if we wanted to only see the data of one store:</p>
<pre><code class="lang-cpp">ulers_data = sales[sales.store==<span class="hljs-string">"Uler"</span>]
ulers_data
</code></pre>
<p>Output:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td></td><td><strong>id</strong></td><td><strong>store</strong></td><td><strong>product_group</strong></td><td><strong>product_code</strong></td><td><strong>stock_qty</strong></td><td><strong>cost</strong></td><td><strong>price</strong></td><td><strong>last_week_sales</strong></td><td><strong>last_month_sales</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>0</strong></td><td>100</td><td>Uler</td><td>PG3</td><td>4000</td><td>731</td><td>921.35</td><td>516.92</td><td>99</td><td>1412</td></tr>
<tr>
<td><strong>2</strong></td><td>102</td><td>Uler</td><td>PG3</td><td>4002</td><td>2729</td><td>608.01</td><td>838.54</td><td>51</td><td>1970</td></tr>
<tr>
<td><strong>3</strong></td><td>103</td><td>Uler</td><td>PG2</td><td>4003</td><td>2217</td><td>577.97</td><td>62.61</td><td>1</td><td>1737</td></tr>
<tr>
<td><strong>5</strong></td><td>105</td><td>Uler</td><td>PG3</td><td>4005</td><td>2183</td><td>254.73</td><td>1274.13</td><td>38</td><td>1264</td></tr>
<tr>
<td><strong>7</strong></td><td>107</td><td>Uler</td><td>PG2</td><td>4007</td><td>2879</td><td>581.86</td><td>385.21</td><td>57</td><td>19</td></tr>
<tr>
<td><strong>19</strong></td><td>119</td><td>Uler</td><td>PG2</td><td>4019</td><td>526</td><td>900.23</td><td>1488.23</td><td>59</td><td>1014</td></tr>
<tr>
<td><strong>36</strong></td><td>136</td><td>Uler</td><td>PG3</td><td>4036</td><td>153</td><td>496.11</td><td>529.48</td><td>94</td><td>543</td></tr>
<tr>
<td><strong>41</strong></td><td>141</td><td>Uler</td><td>PG3</td><td>4041</td><td>885</td><td>349.82</td><td>463.15</td><td>54</td><td>1154</td></tr>
<tr>
<td><strong>49</strong></td><td>149</td><td>Uler</td><td>PG3</td><td>4049</td><td>4249</td><td>297.05</td><td>1018.18</td><td>61</td><td>403</td></tr>
<tr>
<td><strong>50</strong></td><td>150</td><td>Uler</td><td>PG1</td><td>4050</td><td>356</td><td>523.17</td><td>1438.89</td><td>73</td><td>1542</td></tr>
<tr>
<td><strong>52</strong></td><td>152</td><td>Uler</td><td>PG3</td><td>4052</td><td>1863</td><td>298.03</td><td>1038.45</td><td>56</td><td>404</td></tr>
<tr>
<td><strong>54</strong></td><td>154</td><td>Uler</td><td>PG1</td><td>4054</td><td>3997</td><td>737.65</td><td>1396.19</td><td>86</td><td>57</td></tr>
<tr>
<td><strong>56</strong></td><td>156</td><td>Uler</td><td>PG3</td><td>4056</td><td>3481</td><td>369.75</td><td>908.63</td><td>59</td><td>927</td></tr>
<tr>
<td><strong>57</strong></td><td>157</td><td>Uler</td><td>PG3</td><td>4057</td><td>3710</td><td>338.39</td><td>120.02</td><td>57</td><td>1353</td></tr>
<tr>
<td><strong>59</strong></td><td>159</td><td>Uler</td><td>PG2</td><td>4059</td><td>3594</td><td>794.62</td><td>938.82</td><td>27</td><td>844</td></tr>
<tr>
<td><strong>70</strong></td><td>170</td><td>Uler</td><td>PG1</td><td>4070</td><td>1129</td><td>529.48</td><td>1449.53</td><td>98</td><td>321</td></tr>
<tr>
<td><strong>81</strong></td><td>181</td><td>Uler</td><td>PG3</td><td>4081</td><td>4900</td><td>597.64</td><td>220.97</td><td>3</td><td>1231</td></tr>
<tr>
<td><strong>82</strong></td><td>182</td><td>Uler</td><td>PG1</td><td>4082</td><td>826</td><td>308.20</td><td>302.90</td><td>73</td><td>353</td></tr>
<tr>
<td><strong>89</strong></td><td>189</td><td>Uler</td><td>PG3</td><td>4089</td><td>2492</td><td>280.95</td><td>191.82</td><td>7</td><td>357</td></tr>
<tr>
<td><strong>91</strong></td><td>191</td><td>Uler</td><td>PG3</td><td>4091</td><td>4842</td><td>778.14</td><td>332.67</td><td>89</td><td>1931</td></tr>
<tr>
<td><strong>92</strong></td><td>192</td><td>Uler</td><td>PG3</td><td>4092</td><td>2501</td><td>485.57</td><td>309.23</td><td>22</td><td>1931</td></tr>
<tr>
<td><strong>99</strong></td><td>199</td><td>Uler</td><td>PG3</td><td>4099</td><td>1522</td><td>200.72</td><td>1132.09</td><td>58</td><td>933</td></tr>
</tbody>
</table>
</div><p>This will only output a DataFrame containing only the rows where the store column is Uler.</p>
<p>We can also use Pandas to plot the data. For example, let's say we want to plot a histogram of last week's sales of different products.</p>
<pre><code class="lang-cpp"><span class="hljs-keyword">import</span> matplotlib.pyplot as plt
plt.bar(ulers_data[<span class="hljs-string">'last_week_sales'</span>], ulers_data[<span class="hljs-string">'product_code'</span>])
plt.xlabel(<span class="hljs-string">'Product Code'</span>)
plt.ylabel(<span class="hljs-string">'Last week sales'</span>)
plt.title(<span class="hljs-string">'Last week sales of products'</span>)
plt.show()
</code></pre>
<p>Output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1681201183989/83f90fbe-a2cf-4dfd-9a62-f2bd11b6a036.png" alt class="image--center mx-auto" /></p>
<p>We can get the average sales of a specific product group and plot them as well:</p>
<pre><code class="lang-cpp">avg_sales = sales.groupby([<span class="hljs-string">'store'</span>, <span class="hljs-string">'product_group'</span>], as_index=False).agg(avg_sales = (<span class="hljs-string">"last_week_sales"</span>, <span class="hljs-string">"mean"</span>))
avg_sales
</code></pre>
<p>Output:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td></td><td><strong>store</strong></td><td><strong>product_group</strong></td><td><strong>avg_sales</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>0</strong></td><td>Alpino</td><td>PG1</td><td>52.250000</td></tr>
<tr>
<td><strong>1</strong></td><td>Alpino</td><td>PG2</td><td>76.000000</td></tr>
<tr>
<td><strong>2</strong></td><td>Alpino</td><td>PG3</td><td>57.272727</td></tr>
<tr>
<td><strong>3</strong></td><td>Mary</td><td>PG1</td><td>44.800000</td></tr>
<tr>
<td><strong>4</strong></td><td>Mary</td><td>PG2</td><td>49.000000</td></tr>
<tr>
<td><strong>5</strong></td><td>Mary</td><td>PG3</td><td>71.800000</td></tr>
<tr>
<td><strong>6</strong></td><td>Paladin</td><td>PG1</td><td>63.636364</td></tr>
<tr>
<td><strong>7</strong></td><td>Paladin</td><td>PG2</td><td>61.142857</td></tr>
<tr>
<td><strong>8</strong></td><td>Paladin</td><td>PG3</td><td>18.000000</td></tr>
<tr>
<td><strong>9</strong></td><td>Soner</td><td>PG1</td><td>51.000000</td></tr>
<tr>
<td><strong>10</strong></td><td>Soner</td><td>PG2</td><td>51.166667</td></tr>
<tr>
<td><strong>11</strong></td><td>Soner</td><td>PG3</td><td>50.454545</td></tr>
<tr>
<td><strong>12</strong></td><td>Uler</td><td>PG1</td><td>82.500000</td></tr>
<tr>
<td><strong>13</strong></td><td>Uler</td><td>PG2</td><td>36.000000</td></tr>
<tr>
<td><strong>14</strong></td><td>Uler</td><td>PG3</td><td>53.428571</td></tr>
</tbody>
</table>
</div><pre><code class="lang-cpp">avg_sales.plot.bar(x=<span class="hljs-string">"store"</span>, y=<span class="hljs-string">"avg_sales"</span>, color=[<span class="hljs-string">'r'</span>])
</code></pre>
<p>Output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1681201267934/7451451c-abce-4981-9671-ecfdeb0bd403.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-conclusion">Conclusion:</h3>
<p>In this section, we have shown how to use NumPy and Pandas for data analysis. We have demonstrated how to read data from a CSV file into a Pandas DataFrame, compute statistics on the data, filter the data based on certain conditions, and plot the data using Matplotlib.</p>
<p>These are just a few examples of the many things you can do with NumPy and Pandas for data analysis. With these tools, you can quickly and easily analyze large amounts of data, allowing you to gain insights and make informed decisions.</p>
<p>If you like what you are reading, <a target="_blank" href="https://www.buymeacoffee.com/anjaangaire">Buy me a coffee</a>, to support me.</p>
]]></content:encoded></item><item><title><![CDATA[Making your life easier with 'run script' in Django]]></title><description><![CDATA[A basic python script is some code in python that you directly run through the command line and it gives you an output. For example, if you want to print "hello world" 
print("hello world")

You can also save the script in a file and run it through t...]]></description><link>https://blog.sagargaire.com.np/making-your-life-easier-with-run-script-in-django</link><guid isPermaLink="true">https://blog.sagargaire.com.np/making-your-life-easier-with-run-script-in-django</guid><category><![CDATA[Python]]></category><category><![CDATA[Django]]></category><category><![CDATA[Script]]></category><category><![CDATA[runscript]]></category><dc:creator><![CDATA[Sagar Gaire]]></dc:creator><pubDate>Fri, 03 Jun 2022 04:30:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/g5_rxRjvKmg/upload/v1654225616170/Ct_q_5tXz.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A basic python script is some code in python that you directly run through the command line and it gives you an output. For example, if you want to print "hello world" </p>
<pre><code>print(<span class="hljs-string">"hello world"</span>)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654226392242/Xuu2lfxAL.png" alt="Screenshot from 2022-06-03 09-04-11.png" /></p>
<p>You can also save the script in a file and run it through the command line to execute that code.</p>
<pre><code>$ python3 hello.py
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654226610100/nfCYDjvzV.png" alt="Screenshot from 2022-06-03 09-08-18.png" /></p>
<p>These are just a few demos of what you can do in python.</p>
<h3 id="heading-scripts-in-django">Scripts in Django</h3>
<p>After you set up a project in Django, It's quite a hassle to manually check your models and objects through the Django shell command. Let's create a simple Django app (considering you have already installed and set up Django).</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Students</span>(<span class="hljs-params">models.Model</span>):</span>
    first_name = models.CharField(max_length=<span class="hljs-number">200</span>, null=<span class="hljs-literal">True</span>, blank=<span class="hljs-literal">True</span>)
    last_name = models.CharField(max_length=<span class="hljs-number">200</span>, null=<span class="hljs-literal">True</span>, blank=<span class="hljs-literal">True</span>)
    address = models.CharField(max_length=<span class="hljs-number">200</span>, null=<span class="hljs-literal">True</span>, blank=<span class="hljs-literal">True</span>)
    dob = models.DateField(auto_now_add=<span class="hljs-literal">False</span>, null=<span class="hljs-literal">True</span>, blank=<span class="hljs-literal">True</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__str__</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> self.first_name + self.last_name
</code></pre>
<p>After creating the model run makemigrations and migrate command in the command line.</p>
<pre><code>python manage.py makemigrations <span class="hljs-operator">&amp;</span><span class="hljs-operator">&amp;</span> migrate
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654227429997/Lo8mBr8R6.png" alt="Screenshot from 2022-06-03 09-21-55.png" /></p>
<p>Now we can add some students through the Django shell.</p>
<pre><code>python manage.py shell
</code></pre><p>An interactive console will open in your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654227634172/LXVX2221S.png" alt="Screenshot from 2022-06-03 09-25-17.png" /></p>
<p>Now we can create our first student.</p>
<pre><code><span class="hljs-keyword">from</span> students.models <span class="hljs-keyword">import</span> <span class="hljs-title">Students</span>
<span class="hljs-title">Students</span>.<span class="hljs-title">objects</span>.<span class="hljs-title">create</span>(<span class="hljs-title">first_name</span><span class="hljs-operator">=</span><span class="hljs-string">'John'</span>, <span class="hljs-title">last_name</span><span class="hljs-operator">=</span><span class="hljs-string">'Doe'</span>, <span class="hljs-title"><span class="hljs-keyword">address</span></span><span class="hljs-operator">=</span><span class="hljs-string">'12th street, Washington'</span>)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654227971789/TCfpWvCeP.png" alt="Screenshot from 2022-06-03 09-31-01.png" /></p>
<p>This process can be tedious if we have to repeat it for many students and will consume a lot of time. But wait there's an easy trick to do this. This is where Django's runscript command comes in.</p>
<p>In your command line write the following line:</p>
<pre><code><span class="hljs-attribute">pip</span> install django-extensions
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654228438331/EE6om66yM.png" alt="Screenshot from 2022-06-03 09-38-33.png" /></p>
<p>Add it to the INSTALLED_APPS on your settings file:</p>
<pre><code class="lang-python">INSTALLED_APPS = [
    ...,
    <span class="hljs-string">'django_extensions'</span>,
]
</code></pre>
<p>Now we just have to create a folder called scripts inside our main project folder (where our manage.py exists). </p>
<pre><code><span class="hljs-keyword">mkdir</span> scripts
touch scripts/__init_<span class="hljs-number">_</span>.py
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654228803544/-BcdCke18.png" alt="Screenshot from 2022-06-03 09-44-51.png" /></p>
<p>Now we can write our scripts to add, remove or modify our students. Let's create a script to delete all students in our database.</p>
<pre><code><span class="hljs-attribute">touch</span> scripts/delete_all_students.py
</code></pre><pre><code class="lang-python"><span class="hljs-keyword">from</span> students.models <span class="hljs-keyword">import</span> Students

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">run</span>():</span>
    <span class="hljs-comment">#fetch all students</span>
    students = Students.objects.all()
    <span class="hljs-comment">#delete all students</span>
    students.delete()
</code></pre>
<p>Now that our script is ready, we can just run our script through the command line as follows:</p>
<pre><code>python manage.py runscript delete_all_students
</code></pre><p>If you now check the student's model you'll find that all students have been removed. </p>
<pre><code>python manage.py shell
</code></pre><pre><code><span class="hljs-keyword">from</span> students.models <span class="hljs-keyword">import</span> <span class="hljs-title">Students</span>
<span class="hljs-title">Students</span>.<span class="hljs-title">objects</span>.<span class="hljs-title">all</span>()
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1654230121848/wN69oA8Ej.png" alt="Screenshot from 2022-06-03 10-06-47.png" /></p>
<p>We have an empty Queryset here, meaning all the students have been removed.
This is just the tip of the iceberg and you can do almost every shell command from your runscript command. The only limitation is your imagination.</p>
<h4 id="heading-tldr">TLDR;</h4>
<p>You can use <code>python manage.py runscript &lt;script&gt;</code> to run various time-consuming shell commands directly in an instant. If you want to know more about the runscript command visit <a target="_blank" href="https://django-extensions.readthedocs.io/en/latest/runscript.html">here</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Getting started with Python's `super()` function]]></title><description><![CDATA[As we all know, python can do both structural and object-oriented programming. As part of its OOP, it follows one key concept that is inheritance. 
To use the inheritance concept, python uses the super() function to refer to the parent class' methods...]]></description><link>https://blog.sagargaire.com.np/getting-started-with-pythons-super-function</link><guid isPermaLink="true">https://blog.sagargaire.com.np/getting-started-with-pythons-super-function</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[python beginner]]></category><category><![CDATA[functions]]></category><category><![CDATA[inheritance]]></category><dc:creator><![CDATA[Sagar Gaire]]></dc:creator><pubDate>Fri, 03 Sep 2021 11:46:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1630669100483/eYQ07aWWY.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As we all know, python can do both structural and object-oriented programming. As part of its OOP, it follows one key concept that is inheritance. 
To use the inheritance concept, python uses the <code>super()</code> function to refer to the parent class' methods. The <code>super()</code> function used in the child class creates a temporary object of the superclass, that allows the parent class to access the methods of the child class.</p>
<h3 id="benefits-of-super-function">Benefits of <code>super()</code> function:</h3>
<ol>
<li>We don't need to remember the name of the parent class. Calling the <code>super()</code> method will directly access the parent class without specifying the name of the parent class.</li>
<li>We can use it with single or multiple inheritances.</li>
<li>It is better for code reusability and modularity, which helps to keep the DRY(Do not Repeat Yourself)  approach.</li>
<li>The <code>super()</code> function is a dynamic function and goes along with the concept of the dynamically typed programming language of python.</li>
</ol>
<h3 id="limiting-factors-of-super-function">Limiting factors of <code>super()</code> function:</h3>
<ol>
<li>The arguments passed in the <code>super()</code> function and the arguments we have in the super function should match.</li>
<li>Every time we call the super method the keyword <code>super()</code> should be used.</li>
<li>We have to specify the exact class and methods present, which are referred to by the <code>super()</code> function.</li>
</ol>
<h3 id="using-super-function-in-inheritance">Using <code>super()</code> function in inheritance</h3>
<p>Let us have a rectangle and a square function that is used to calculate the area and perimeter of the rectangle and the square. Normally what we do is the following:</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Rectangle</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, length, width</span>):</span>
        self.length = length
        self.width = width

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">area</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> self.length*self.width

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">perimeter</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> <span class="hljs-number">2</span>*self.length + <span class="hljs-number">2</span>*self.width


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Square</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, length</span>):</span>
        self.length = length

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">area</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> self.length**<span class="hljs-number">2</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">perimeter</span>(<span class="hljs-params">self</span>):</span>
       <span class="hljs-keyword">return</span> <span class="hljs-number">4</span>*self.length()
</code></pre>
<p>These are two simple classes Rectangle and Square. You can use these as:</p>
<pre><code class="lang-sh">
&gt;&gt;&gt; square = Square(7)
&gt;&gt;&gt; square.area()
49
&gt;&gt;&gt; rectangle = Rectangle(5,2)
&gt;&gt;&gt; rectangle.perimeter()
14
</code></pre>
<p>A square is a special type of rectangle which have both of its sides equal to each other. So we can use inheritance in the Square class to reduce the code.</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Rectangle</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, length, width</span>):</span>
        self.length = length
        self.width = width

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">area</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> self.length * self.width

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">perimeter</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> <span class="hljs-number">2</span> * self.length + <span class="hljs-number">2</span> * self.width

<span class="hljs-comment">#We'll declare that the Square class inherits from the Rectangle class</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Square</span>(<span class="hljs-params">Rectangle</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, length</span>):</span>
        super().__init__(length, length)
</code></pre>
<p>Here we've used the <code>super()</code>  function to call the <code>__init__()</code>  method of the Rectangle class, allowing us to use it in the Square class without repeating the same code twice. The core functionality remains the same after using the <code>super()</code> method:</p>
<pre><code class="lang-sh">&gt;&gt;&gt; square = Square(5)
&gt;&gt;&gt; square.area()
25
&gt;&gt;&gt; square.perimeter()
20
</code></pre>
<p>Behind the scenes, when we call the <code>Square(5)</code> method, it goes on to the <code>__init__()</code> method and see the <code>super()</code> method which then calls the <code>__init__()</code> method of the Rectangle class and pass the length twice as arguments for length and width. After the Square is initialized, all other functions of the Rectangle can be used by it, allowing us to use them wherever we like.</p>
<h3 id="conclusion">Conclusion</h3>
<p>The <code>super()</code> method is a very useful method in python that is used while applying the inheritance of classes. It can be used with multiple inheritances as well. </p>
]]></content:encoded></item><item><title><![CDATA[How to install Django?]]></title><description><![CDATA[Django: The web framework for perfectionists with deadlines.
From Django's official site:

 Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of m...]]></description><link>https://blog.sagargaire.com.np/how-to-install-django</link><guid isPermaLink="true">https://blog.sagargaire.com.np/how-to-install-django</guid><category><![CDATA[Python]]></category><category><![CDATA[Django]]></category><category><![CDATA[Ubuntu]]></category><dc:creator><![CDATA[Sagar Gaire]]></dc:creator><pubDate>Sun, 29 Aug 2021 13:40:25 GMT</pubDate><content:encoded><![CDATA[<h2 id="django-the-web-framework-for-perfectionists-with-deadlines">Django: The web framework for perfectionists with deadlines.</h2>
<p>From Django's <a target="_blank" href="https://www.djangoproject.com/">official site</a>:</p>
<blockquote>
<p> Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. </p>
</blockquote>
<hr />
<h3 id="djangos-advantages">Django's Advantages</h3>
<p>If you are getting started with web development, then Django is a well-known Python web framework for easy and faster development. The best selling point of Django are:</p>
<ol>
<li>Ridiculously fast: <br />
 Django was designed to help developers take applications from concept to completion as quickly as 
 possible.</li>
<li>Reassuringly secure:<br />
 Django takes security seriously and helps developers avoid many common security mistakes.</li>
<li>Exceedingly scalable:<br />
 Some of the busiest sites on the web leverage Django’s ability to quickly and flexibly scale.</li>
</ol>
<h3 id="getting-started">Getting Started</h3>
<p>Before starting your way into Django, basic knowledge of Python is recommended. If you have prior knowledge of Python or any other programming languages, you'll be able to grasp the concepts easily.
The requirements for getting started with Django are:</p>
<ol>
<li><h4 id="pythonlessbr-greater">Python:<br /></h4>
<p> Django is based on python, so you'll need to install python on your machine to get started with 
 Django. You can install python on your machine from <a target="_blank" href="https://www.python.org/downloads/">here</a>.
 You can choose which operating system you are on and follow the instructions there. Install the latest package available or if you want any specific version then you are free to choose on your own. I'll be using python 3.8 in this guide.<br />
You can check if python is installed on your machine or not by this simple command. You should see something like this. <br /></p>
<pre><code class="lang-sh">$ python -V
 Python 3.8.10
</code></pre>
</li>
<li><h4 id="virtual-environmentlessbr-greater">Virtual environment:<br /></h4>
<p> Python applications will often use multiple packages and modules other than those provided with the standard library. Some applications require one version of the same package while others require another version. Managing multiple versions of the same package can be difficult, but you don't have to worry because the virtual environment is on the rescue. The basic functionality of a virtual environment is to isolate an application from another application so that any modules used on one application will not interfere with another application. <br />
You can install the virtual environment through pip, python's package manager if you are using python2. If you are using python3 then the virtual environment comes along with the python installation. I'm only focusing on python3 here.<br />
Open up your terminal and type this:</p>
<pre><code class="lang-sh">mkdir django_project &amp;&amp; <span class="hljs-built_in">cd</span> django_project
python -m venv env
</code></pre>
<p>This will create a folder called django-project and inside the project folder, a virtual environment named env. To activate this virtual environment run the following command:<br /></p>
<pre><code class="lang-sh"><span class="hljs-built_in">source</span> env/bin/activate
</code></pre>
<p>After activating the virtual environment, you'll see (env) in front of your shell. Now you are ready to move to the next step.</p>
</li>
<li><h4 id="django-lessbr-greater">Django :<br /></h4>
<p>After you have activated your virtual environment, install Django on your virtual environment with this command:</p>
<pre><code class="lang-sh">python -m pip install django
</code></pre>
<p>It will install the latest release of the Django package available. If you want to use any specific version of Django then you can specify the version in the command while installing Django.</p>
<pre><code class="lang-sh">python -m pip install django==3.1.0
</code></pre>
<p>Now you are ready to write your first program with Django.</p>
</li>
</ol>
<p>That's all for this article. I'll update the basic learning approach on Django soon. Feel free to leave comments below if you have any doubts on anything, I'll try to answer all of them.</p>
]]></content:encoded></item></channel></rss>