<?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 Rakesh Reddy Nallagondla on Medium]]></title>
        <description><![CDATA[Stories by Rakesh Reddy Nallagondla on Medium]]></description>
        <link>https://medium.com/@rakeshreddyn7?source=rss-2fb26e12c93f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uYATcXhH4K5Jysst5ln6Yg.jpeg</url>
            <title>Stories by Rakesh Reddy Nallagondla on Medium</title>
            <link>https://medium.com/@rakeshreddyn7?source=rss-2fb26e12c93f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:09:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rakeshreddyn7/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[Welcome to Pandas — Mastering Data with Python (Part 1)]]></title>
            <link>https://medium.com/@rakeshreddyn7/welcome-to-pandas-mastering-data-with-python-part-1-1bd938a0c7a2?source=rss-2fb26e12c93f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bd938a0c7a2</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[pandas-series]]></category>
            <category><![CDATA[pandas-dataframe]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rakesh Reddy Nallagondla]]></dc:creator>
            <pubDate>Wed, 09 Apr 2025 06:20:48 GMT</pubDate>
            <atom:updated>2025-04-09T06:20:48.138Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*PO6Owm0IODg7sywvduQGXA.png" /><figcaption>Pandas — Python Data Analysis</figcaption></figure><h3>Welcome to Pandas — Mastering Data with Python (Part 1)</h3><p>If you’re comfortable with NumPy or just stepping into the world of <strong>Data Science</strong>, <strong>Analytics</strong>, or <strong>Machine Learning</strong>, then <strong>Pandas</strong> is your next big leap.<br>Think of Pandas as your personal assistant when it comes to organizing, analyzing, and manipulating structured data — like tables, CSVs, or Excel sheets.</p><p>In this blog (Part 1), we’ll walk through the <strong>fundamentals of Pandas</strong> in a way that’s easy to understand and follow along — with real examples, detailed outputs, and short explanations that stick.</p><p>The name is derived from the term <strong>panel data</strong>, an econometrics term for <strong>data sets</strong> that include observations over multiple time periods for the same individuals, as well as a play on the phrase <strong>Python data analysis</strong>.</p><h3>What is Pandas?</h3><p><strong>Pandas</strong> is an open-source Python library built on top of <strong>NumPy</strong>, and it’s designed specifically for <strong>data manipulation and analysis</strong>.<br>It introduces two powerful data structures: <strong>Series</strong> (like a column) and <strong>DataFrame</strong> (like a full table) that make it super easy to work with rows and columns of data.</p><p>It was originally created by <strong>Wes McKinney</strong> in <strong>2008</strong> to address Python’s lack of robust tools for time series and financial data analysis.<br>Today, it’s one of the most popular libraries in the Python ecosystem — widely used in data science, machine learning, finance, and business intelligence.</p><h3>What You’ll Learn in This Blog (Part 1)</h3><p>This blog is your beginner-friendly guide to <strong>understanding and working with Pandas step-by-step</strong>.</p><p>By the end of this blog, you’ll be able to:</p><ul><li>Create and explore <strong>Pandas Series</strong></li><li>Use powerful operations on Series (head, tail, indexing, value counts, etc.)</li><li>Build <strong>DataFrames</strong> from lists, dictionaries, and files (like CSV)</li><li>Access and manipulate columns and rows using .iloc, .loc, and conditions</li><li>View properties like shape, dtypes, and info</li><li>Filter data by column names, data types, or string patterns</li><li>Assign custom index to your DataFrame using set_index</li><li>Rename columns for clarity</li></ul><p>For now, let’s focus on building a solid foundation — and we’ll level up in Part 2!</p><h3>Why Pandas?</h3><p>Python already has built-in lists and dictionaries — so why use Pandas?</p><ul><li>It’s <strong>faster</strong>, more <strong>efficient</strong>, and <strong>easier</strong> for real-world data analysis.</li><li>It comes with <strong>built-in functions</strong> that save you hundreds of lines of code.</li><li>Pandas works perfectly with tools like <strong>NumPy</strong>, <strong>Matplotlib</strong>, <strong>Seaborn</strong>, and <strong>Scikit-learn</strong>.</li></ul><p>If you’re planning to do <strong>data wrangling</strong>, <strong>EDA (Exploratory Data Analysis)</strong>, or even just analyze a CSV file, Pandas will be your go-to tool.</p><h3>Let’s Import the Essentials</h3><p>We’ll first explore the basics of <strong>Pandas Series</strong> — how to create, access, and manipulate them — and then we’ll move on to working with <strong>DataFrames</strong>, which are more powerful and widely used for real-world data analysis.</p><p><strong>Note:</strong> Don’t skip over the print statements in the code blocks — they’re not just for output! They often include short explanations, real insights, and key observations that help you understand what’s really going on behind the scenes.</p><p>Before we begin, let’s import the libraries we’ll use throughout the blog:</p><pre>import numpy as np<br>import pandas as pd</pre><h3>Creating a Pandas Series — You Can Do It Different Ways</h3><p>In this section, let’s look at a few different ways you can create a <strong>Pandas Series</strong> — which is basically a one-dimensional labeled array that can hold any kind of data (like numbers, strings, etc.).</p><ul><li>You can create a Series from a <strong>NumPy array</strong>. If you don’t specify an index, Pandas will automatically give it default integer indexes starting from 0.</li><li>You can quickly preview the first few or last few elements using .head() and .tail().</li></ul><p>You can assign your own <strong>custom index</strong> using something like np.arange(10, 16). This helps if you want more meaningful or specific labels instead of 0, 1, 2…</p><p>You can also build a Series directly from a <strong>Python dictionary</strong>. In that case, the keys in the dictionary become the index, and the values become the actual data.</p><p>You’re not limited to just raw data either — you can name your Series and its index:</p><ul><li>series.name gives a name to the Series (like a column title).</li><li>series.index.name lets you label the index axis.</li></ul><p>You can even create a Series from a <strong>single scalar value</strong>, like 5, and repeat it across a custom list of index values. Handy when you want to fill in default values.</p><p>So as you can see — whether it’s from an array, dictionary, or just a single value — Pandas makes it really easy to create Series your way.</p><pre># ===================================================================================<br># Creating Pandas Series: from np.array, from dict, with scalar, with predefined index<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>series_data = np.array([&#39;H&#39;, &#39;i&#39;, &#39;i&#39;, 1, 1, 3])<br>series_from_nparray = pd.Series(series_data)<br>print(&quot;Pandas Series from NumPy array --&gt;\n&quot;, series_from_nparray)<br>print(&quot;Pandas Series with head(3) --&gt;\n&quot;, series_from_nparray.head(3)) #by default 5 rows<br>print(&quot;Pandas Series with tail(3) --&gt;\n&quot;, series_from_nparray.tail(3)) #by default 5 rows<br>print(&quot;===================================================================================&quot;)<br><br>series_with_predefined_index = pd.Series(series_data, index=np.arange(10,16))<br>print(&quot;Pandas Series with predefined index --&gt;\n&quot;, series_with_predefined_index)<br>print(&quot;===================================================================================&quot;)<br><br>dict_1 = {&#39;p&#39;:112, &#39;q&#39;:113, &#39;r&#39;:114}<br>series_from_dict = pd.Series(dict_1)<br>print(&quot;Pandas Series from Python dict --&gt;\n&quot;, series_from_dict)<br>print(&quot;===================================================================================&quot;)<br><br>series_from_dict.name = &#39;ascii_values&#39;<br>series_from_dict.index.name = &quot;alphabets&quot;<br>print(&quot;Pandas Series with index name and column name --&gt; \n&quot;, series_from_dict)<br>print(&quot;===================================================================================&quot;)<br><br>series_with_scalar = pd.Series(5, index=[&#39;a&#39;,&#39;b&#39;,&#39;c&#39;])<br>print(&quot;Pandas Series with a scalar --&gt;\n&quot;, series_with_scalar)<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Pandas Series from NumPy array --&gt;<br> 0    H<br>1    i<br>2    i<br>3    1<br>4    1<br>5    3<br>dtype: object<br>Pandas Series with head(3) --&gt;<br> 0    H<br>1    i<br>2    i<br>dtype: object<br>Pandas Series with tail(3) --&gt;<br> 3    1<br>4    1<br>5    3<br>dtype: object<br>===================================================================================<br>Pandas Series with predefined index --&gt;<br> 10    H<br>11    i<br>12    i<br>13    1<br>14    1<br>15    3<br>dtype: object<br>===================================================================================<br>Pandas Series from Python dict --&gt;<br> p    112<br>q    113<br>r    114<br>dtype: int64<br>===================================================================================<br>Pandas Series with index name and column name --&gt; <br> alphabets<br>p    112<br>q    113<br>r    114<br>Name: ascii_values, dtype: int64<br>===================================================================================<br>Pandas Series with a scalar --&gt;<br> a    5<br>b    5<br>c    5<br>dtype: int64<br>===================================================================================</pre><h3>Exploring a Pandas Series — You Can Check Its Structure and Content</h3><p>Once you’ve created a Pandas Series, you can explore its <strong>structure</strong>, <strong>data type</strong>, and even the <strong>distribution of values</strong> with just a few lines.</p><p>Let’s break it down:</p><ul><li>You can use .index to see the labels (indexes) and .values to get the actual data inside.</li><li>If you’re using a scalar Series (like repeating a number), .index still shows the custom labels you gave it.</li></ul><p>You can also get useful metadata about the Series:</p><ul><li>.shape tells you the number of elements (in tuple form),</li><li>.size gives the total count,</li><li>.empty checks if the Series has any data at all,</li><li>.ndim gives the number of dimensions (should be 1 for a Series),</li><li>.dtype reveals the data type stored in the Series.</li></ul><p>Want to know how often each value appears? Use .value_counts() — it’s super useful for analyzing <strong>frequency</strong>.</p><p>And when you’re dealing with missing data, .isnull() and .notnull() help you find out where the nulls are and where they aren&#39;t. These are especially used when you’re cleaning or preprocessing data.</p><p>So whenever you’re working with a Series, these properties and functions let you peek under the hood and understand your data better.</p><pre># ===================================================================================<br># Exploring Properties of Series: index, values, shape, size, ndim, dtype, value_counts, isnull, notnull<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Index of series_from_nparray --&gt;&quot;, series_from_nparray.index)<br>print(&quot;Values of series_from_nparray --&gt;&quot;, series_from_nparray.values)<br>print(&quot;Index of series_with_scalar --&gt;&quot;, series_with_scalar.index)<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Shape --&gt;&quot;, series_from_nparray.shape)<br>print(&quot;Size --&gt;&quot;, series_from_nparray.size)<br>print(&quot;Is Empty? --&gt;&quot;, series_from_nparray.empty)<br>print(&quot;Dimensions --&gt;&quot;, series_from_nparray.ndim)<br>print(&quot;Data type of an element --&gt;&quot;, series_from_dict.dtype)<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Value Counts --&gt;\n&quot;, series_from_nparray.value_counts())<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Check for nulls --&gt;\n&quot;, series_from_nparray.isnull())<br>print(&quot;Check for non nulls --&gt;\n&quot;, series_from_nparray.notnull())<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Index of series_from_nparray --&gt; RangeIndex(start=0, stop=6, step=1)<br>Values of series_from_nparray --&gt; [&#39;H&#39; &#39;i&#39; &#39;i&#39; &#39;1&#39; &#39;1&#39; &#39;3&#39;]<br>Index of series_with_scalar --&gt; Index([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;], dtype=&#39;object&#39;)<br>===================================================================================<br>Shape --&gt; (6,)<br>Size --&gt; 6<br>Is Empty? --&gt; False<br>Dimensions --&gt; 1<br>Data type of an element --&gt; int64<br>===================================================================================<br>Value Counts --&gt;<br> i    2<br>1    2<br>H    1<br>3    1<br>Name: count, dtype: int64<br>===================================================================================<br>Check for nulls --&gt;<br> 0    False<br>1    False<br>2    False<br>3    False<br>4    False<br>5    False<br>dtype: bool<br>Check for non nulls --&gt;<br> 0    True<br>1    True<br>2    True<br>3    True<br>4    True<br>5    True<br>dtype: bool<br>===================================================================================</pre><h3>Accessing, Transforming, and Sorting in a Pandas Series</h3><p>Once your Series is ready, you can easily access individual elements or transform the data using some functions.</p><ul><li>To <strong>access a value</strong>, you can use either its position (like series[2]) or its label (like series[&#39;p&#39;] if it&#39;s created from a dictionary).</li><li>You can slice it like a list (series[1:4]) or use .get(index) to safely fetch values.</li></ul><p>You can also <strong>perform operations</strong> directly on the entire Series:</p><ul><li>If the Series has strings, multiplying it by 2 repeats each element.</li><li>If the Series has numbers, multiplying it by 2 does element-wise multiplication.</li></ul><p>Want to convert your Series to another format? You can:</p><ul><li>Use .to_dict() to turn it into a Python dictionary.</li><li>Use .to_list() to get a simple list of values.</li></ul><p>And when it comes to organizing data:</p><ul><li>.sort_values() helps you sort the Series based on the values.</li><li>.sort_index() lets you sort it based on the index.</li></ul><p>All of this makes it super easy to explore, format, or reshape your Series just the way you want.</p><pre># ===================================================================================<br># Accessing, transforming &amp; Sorting : to_dict, to_list, sort_values, sort_index<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Element at index 2 --&gt;&quot;, series_from_nparray[2])<br>print(&quot;Element with label &#39;p&#39; --&gt;&quot;, series_from_dict[&#39;p&#39;])<br>print(&quot;Slicing by position [1:4] --&gt;\n&quot;, series_from_nparray[1:4])<br>print(&quot;Get value for index 2 --&gt;&quot;, series_from_nparray.get(2))<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Multiply series(with strings) by 2 --&gt;\n&quot;, series_from_nparray*2)<br>print(&quot;Multiply series(int only) by 2 --&gt;\n&quot;, series_from_dict*2)<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Convert Series to dict --&gt;&quot;, series_from_nparray.to_dict())<br>print(&quot;Convert Series to list --&gt;&quot;, series_from_nparray.to_list())<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Sorted by values --&gt;\n&quot;, series_from_nparray.sort_values())<br>print(&quot;Sorted by index --&gt;\n&quot;, series_from_nparray.sort_index())<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Element at index 2 --&gt; i<br>Element with label &#39;p&#39; --&gt; 112<br>Slicing by position [1:4] --&gt;<br> 1    i<br>2    i<br>3    1<br>dtype: object<br>Get value for index 2 --&gt; i<br>===================================================================================<br>Multiply series(with strings) by 2 --&gt;<br> 0    HH<br>1    ii<br>2    ii<br>3    11<br>4    11<br>5    33<br>dtype: object<br>Multiply series(int only) by 2 --&gt;<br> alphabets<br>p    224<br>q    226<br>r    228<br>Name: ascii_values, dtype: int64<br>===================================================================================<br>Convert Series to dict --&gt; {0: &#39;H&#39;, 1: &#39;i&#39;, 2: &#39;i&#39;, 3: &#39;1&#39;, 4: &#39;1&#39;, 5: &#39;3&#39;}<br>Convert Series to list --&gt; [&#39;H&#39;, &#39;i&#39;, &#39;i&#39;, &#39;1&#39;, &#39;1&#39;, &#39;3&#39;]<br>===================================================================================<br>Sorted by values --&gt;<br> 3    1<br>4    1<br>5    3<br>0    H<br>1    i<br>2    i<br>dtype: object<br>Sorted by index --&gt;<br> 0    H<br>1    i<br>2    i<br>3    1<br>4    1<br>5    3<br>dtype: object<br>===================================================================================</pre><h3>Some More Useful Functions You Can Try on a Pandas Series</h3><p>Let’s now look at a few more functions that help you quickly <strong>summarize</strong>, <strong>analyze</strong>, or <strong>explore</strong> your Series data.</p><ul><li>The .describe() function gives you a summary of the Series. If the Series has numbers, it returns stats like count, mean, min, max, and standard deviation. If the Series has strings or mixed types, it returns things like count, unique values, top value, and frequency.</li><li>You can use .sum() to get the total of all elements. If the Series has strings or a mix, it’ll try to concatenate or work with the compatible types. For numeric Series, it just adds up the numbers.</li><li>.max() and .min() let you quickly find the highest and lowest values in the Series.</li><li>And .unique() returns all the <strong>distinct values</strong> in the Series — very useful for understanding your data at a glance.</li></ul><p>These functions are super useful when you want to explore a dataset, debug, or just do a quick sanity check on what kind of values you’re working with.</p><pre># ===================================================================================<br># Some more useful functions : describe, sum, max, min, unique<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Describe Series with str --&gt;\n&quot;, series_from_dict.describe())<br>print(&quot;Describe Series with int and str --&gt;\n&quot;, series_from_nparray.describe())<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Series sum with str and int --&gt;&quot;, series_from_nparray.sum())<br>print(&quot;Series sum with int --&gt;&quot;, series_from_dict.sum())<br>print(&quot;Maximum element in Series --&gt;&quot;, series_from_dict.max())<br>print(&quot;Minimum element in Series --&gt;&quot;, series_from_dict.min())<br>print(&quot;Unique values in Series --&gt;\n&quot;, series_from_nparray.unique())<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Describe Series with str --&gt;<br> count      3.0<br>mean     113.0<br>std        1.0<br>min      112.0<br>25%      112.5<br>50%      113.0<br>75%      113.5<br>max      114.0<br>Name: ascii_values, dtype: float64<br>Describe Series with int and str --&gt;<br> count     6<br>unique    4<br>top       i<br>freq      2<br>dtype: object<br>===================================================================================<br>Series sum with str and int --&gt; Hii113<br>Series sum with int --&gt; 339<br>Maximum element in Series --&gt; 114<br>Minimum element in Series --&gt; 112<br>Unique values in Series --&gt;<br> [&#39;H&#39; &#39;i&#39; &#39;1&#39; &#39;3&#39;]<br>===================================================================================</pre><h3>Creating a DataFrame from a Dictionary — The Easiest Way to Get Started</h3><p>Now that you’ve seen what a Pandas Series is and how flexible it can be, it’s time to <strong>step up</strong> to something more powerful — the <strong>Pandas DataFrame</strong>.</p><p>A <strong>DataFrame</strong> is like a full table — think of it as an Excel sheet or a SQL table in Python. It’s two-dimensional and can store multiple columns of different data types.</p><p>Let’s start by creating a DataFrame from a simple dictionary and understand how it works.</p><p>Pandas makes it really simple to build a <strong>DataFrame</strong> from a Python dictionary.<br>Each key in the dictionary becomes a column in the DataFrame, and the values (as lists) become the rows for that column.</p><p>In this example, we’re creating a small dataset of cars with details like:</p><ul><li><strong>Make</strong> and <strong>Model</strong></li><li><strong>Year of manufacturing</strong></li><li><strong>Fuel type</strong></li><li><strong>Mileage</strong></li><li><strong>Price</strong></li></ul><p>You just need to pass the dictionary to pd.DataFrame() and Pandas takes care of the rest — assigning columns, row numbers (as default index), and structuring the data neatly.</p><p>You’ll notice that:</p><ul><li>The mileage for one of the cars is None. Pandas represents this as NaN, which is how it handles missing data by default.</li></ul><p>This is a very common and readable way to create quick test datasets or small structured tables for learning or analysis.</p><pre># ===================================================================================<br># Creating Pandas DataFrame : pd.DataFrame from dict<br># ===================================================================================<br>car_data = {<br>    &#39;Make&#39;: [&#39;Toyota&#39;, &#39;Honda&#39;, &#39;Ford&#39;, &#39;Tesla&#39;, &#39;BMW&#39;],<br>    &#39;Model&#39;: [&#39;Corolla&#39;, &#39;Civic&#39;, &#39;F-150&#39;, &#39;Model 3&#39;, &#39;3 Series&#39;],<br>    &#39;Year&#39;: [2020, 2019, 2018, 2021, 2020],<br>    &#39;Fuel_Type&#39;: [&#39;Petrol&#39;, &#39;Petrol&#39;, &#39;Diesel&#39;, &#39;Electric&#39;, &#39;Petrol&#39;],<br>    &#39;Mileage(kmpl)&#39;: [18, 17.5, 12, None, 15],<br>    &#39;Price(USD)&#39;: [18000, 17500, 22000, 35000, 41000]<br>}<br>df_cars_with_dict = pd.DataFrame(car_data)<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Car DataFrame from dict --&gt;\n&quot;, df_cars_with_dict)<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Car DataFrame from dict --&gt;<br>      Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>0  Toyota   Corolla  2020    Petrol           18.0       18000<br>1   Honda     Civic  2019    Petrol           17.5       17500<br>2    Ford     F-150  2018    Diesel           12.0       22000<br>3   Tesla   Model 3  2021  Electric            NaN       35000<br>4     BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================</pre><h3>Creating a DataFrame from a List (with Custom Column Names)</h3><p>Another way to create a DataFrame is by using a <strong>list of lists</strong>, where each inner list represents a row of data.</p><p>In this case:</p><ul><li>Each sublist contains details about a specific car (make, model, year, fuel type, mileage, and price).</li><li>To label the columns meaningfully, we provide a separate list called column_names.</li></ul><p>You just pass both to pd.DataFrame() — the list as data and the column names as the columns parameter.</p><p>This method is especially useful when:</p><ul><li>You already have data in row-wise format (like from CSV or a loop).</li><li>You want to quickly plug in structured data and give proper labels.</li></ul><p>Just like before, Pandas automatically handles missing values (None becomes NaN) and assigns row indices starting from 0 by default.</p><pre># ===================================================================================<br># Creating Pandas DataFrame : pd.DataFrame from list and giving column_names separate<br># ===================================================================================<br>car_data_list = [<br>    [&#39;Toyota&#39;, &#39;Corolla&#39;, 2020, &#39;Petrol&#39;, 18, 18000],<br>    [&#39;Honda&#39;, &#39;Civic&#39;, 2019, &#39;Petrol&#39;, 17.5, 17500],<br>    [&#39;Ford&#39;, &#39;F-150&#39;, 2018, &#39;Diesel&#39;, 12, 22000],<br>    [&#39;Tesla&#39;, &#39;Model 3&#39;, 2021, &#39;Electric&#39;, None, 35000],<br>    [&#39;BMW&#39;, &#39;3 Series&#39;, 2020, &#39;Petrol&#39;, 15, 41000]<br>]<br>column_names = [&#39;Make&#39;, &#39;Model&#39;, &#39;Year&#39;, &#39;Fuel_Type&#39;, &#39;Mileage(kmpl)&#39;, &#39;Price(USD)&#39;]<br>df_cars_with_list = pd.DataFrame(car_data_list, columns=column_names) # same with the numpy arrays but you define np.array(car_data_list)<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Car DataFrame from list --&gt;\n&quot;, df_cars_with_list)<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Car DataFrame from list --&gt;<br>      Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>0  Toyota   Corolla  2020    Petrol           18.0       18000<br>1   Honda     Civic  2019    Petrol           17.5       17500<br>2    Ford     F-150  2018    Diesel           12.0       22000<br>3   Tesla   Model 3  2021  Electric            NaN       35000<br>4     BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================</pre><h3>Creating a DataFrame by Reading a CSV File</h3><p>Instead of manually entering data, you can load a <strong>CSV (Comma-Separated Values)</strong> file directly into a Pandas DataFrame using pd.read_csv().</p><p>All you need is the file path — and Pandas takes care of reading the data, assigning headers, and creating the DataFrame.</p><p>This is one of the most common ways you’ll work with data in the real world — especially when importing datasets from external sources or exporting reports.</p><p>You can also read data from other formats using:</p><ul><li>pd.read_excel() – for Excel files (.xlsx)</li><li>pd.read_json() – for JSON files</li><li>pd.read_parquet() – for Parquet files (often used in big data pipelines)</li><li>pd.read_pickle() – for reading pickled Python objects</li></ul><p>This flexibility is one of the reasons Pandas is so powerful in data engineering and analysis tasks.</p><pre># ===================================================================================<br># Creating Pandas DataFrame : from reading csv file<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>car_data_csv = pd.read_csv(r&quot;C:\Users\rakes\Desktop\Learnings\Data-Engineering\Pyspark\car_data.csv&quot;)<br>print(&quot;Car DataFrame from csv --&gt;\n&quot;, car_data_csv)<br>print(&quot;===================================================================================&quot;)<br><br># df_excel = pd.read_excel(&quot;data.xlsx&quot;, sheet_name=&quot;Sheet1&quot;)<br># df_json = pd.read_json(&quot;data.json&quot;)<br># df_parquet = pd.read_parquet(&quot;data.parquet&quot;)<br># df_pickle = pd.read_pickle(&quot;data.pkl&quot;)</pre><pre>===================================================================================<br>Car DataFrame from csv --&gt;<br>      Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>0  Toyota   Corolla  2020    Petrol           18.0       18000<br>1   Honda     Civic  2019    Petrol           17.5       17500<br>2    Ford     F-150  2018    Diesel           12.0       22000<br>3   Tesla   Model 3  2021  Electric            NaN       35000<br>4     BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================</pre><h3>Setting a Custom Index and Renaming Columns in a DataFrame</h3><p>By default, Pandas assigns a numeric index (0, 1, 2, …) to each row in a DataFrame. But sometimes, you might want to use your own custom values as row identifiers — like user IDs, order numbers, or any unique label.</p><p>You can do this using .set_index() by passing the column you want to turn into the index.<br>If you use inplace=True, the change will be applied directly to the original DataFrame.</p><p>In the second part, we rename a column using .rename().<br>This is helpful when you want to clean up column names for clarity — maybe to remove special characters or make the names more readable.<br>Here, we renamed &quot;Price(USD)&quot; to &quot;Price(US Dollar)&quot; for better clarity.</p><p>These kinds of small customizations make your data cleaner, easier to read, and more intuitive to work with.</p><pre># ===================================================================================<br># Assiging user index to the DataFrame with set_index, Renaming the columns<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>num_rows = len(car_data_csv)<br>ids = [12123, 31212, 42332, 23443, 17645]<br>car_data_csv[&#39;id&#39;] = ids<br>car_data_csv.set_index(&#39;id&#39;, inplace=True) # Setting inplace=True directly modifies the DataFrame.<br>print(&quot;Car Dataframe with manual index --&gt;\n&quot;, car_data_csv)<br>print(&quot;===================================================================================&quot;)<br><br>car_data_csv_renamed = car_data_csv.rename(columns={&#39;Price(USD)&#39;:&#39;Price(US Dollar)&#39;})<br>print(&quot;Car DataFrame with renamed column --&gt;\n&quot;, car_data_csv_renamed)</pre><pre>===================================================================================<br>Car Dataframe with manual index --&gt;<br>          Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>id                                                                <br>12123  Toyota   Corolla  2020    Petrol           18.0       18000<br>31212   Honda     Civic  2019    Petrol           17.5       17500<br>42332    Ford     F-150  2018    Diesel           12.0       22000<br>23443   Tesla   Model 3  2021  Electric            NaN       35000<br>17645     BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================<br>Car DataFrame with renamed column --&gt;<br>          Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(US Dollar)<br>id                                                                      <br>12123  Toyota   Corolla  2020    Petrol           18.0             18000<br>31212   Honda     Civic  2019    Petrol           17.5             17500<br>42332    Ford     F-150  2018    Diesel           12.0             22000<br>23443   Tesla   Model 3  2021  Electric            NaN             35000<br>17645     BMW  3 Series  2020    Petrol           15.0             41000</pre><h3>Exploring Basic DataFrame Properties</h3><p>Now that we’ve created our DataFrame, let’s take a moment to explore its basic structure.</p><ul><li>You can use .head(n) and .tail(n) to preview the <strong>first or last n rows</strong> of your data. If you don’t pass a number, it defaults to 5.</li><li>.shape gives you the number of <strong>rows and columns</strong> — for quickly checking the size of your dataset.</li><li>.columns lists all the <strong>column names</strong> in the DataFrame.</li><li>.index shows the row labels — which is especially useful if you’ve set a custom index (like we did earlier).</li></ul><p>To get a <strong>summary of the dataset</strong>, including column names, data types, and non-null values, you can use .info().</p><p>And if you just want to know the <strong>data type of each column</strong> (e.g., int, float, object), .dtypes is your go-to.</p><p>This kind of quick inspection helps you understand your dataset better before diving into deeper analysis or transformations.</p><pre># ===================================================================================<br># Properties of DataFrame: head, tail, shape, columns, index, info, dtypes<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>print(&quot;First 2 columns of car data --&gt;\n&quot;, car_data_csv.head(2))<br>print(&quot;Last 2 columns of car data --&gt;\n&quot;, car_data_csv.tail(2))<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Shape of the DataFrame RowsxColumns --&gt;&quot;,car_data_csv.shape)<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Column names of the DataFrame --&gt;&quot;, car_data_csv.columns) #car_data_csv.columns.to_list() - if you just need column names in output<br>print(&quot;Indices of the DataFrame --&gt;&quot;, car_data_csv.index)<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Info : Column name, Non-null count, Datatype --&gt;&quot;)<br>print(car_data_csv.info())<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Datatypes of the columns in a DataFrame --&gt;\n&quot;, car_data_csv.dtypes)<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>First 2 columns of car data --&gt;<br>          Make    Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>id                                                               <br>12123  Toyota  Corolla  2020    Petrol           18.0       18000<br>31212   Honda    Civic  2019    Petrol           17.5       17500<br>Last 2 columns of car data --&gt;<br>         Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>id                                                               <br>23443  Tesla   Model 3  2021  Electric            NaN       35000<br>17645    BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================<br>Shape of the DataFrame RowsxColumns --&gt; (5, 6)<br>===================================================================================<br>Column names of the DataFrame --&gt; Index([&#39;Make&#39;, &#39;Model&#39;, &#39;Year&#39;, &#39;Fuel_Type&#39;, &#39;Mileage(kmpl)&#39;, &#39;Price(USD)&#39;], dtype=&#39;object&#39;)<br>Indices of the DataFrame --&gt; Index([12123, 31212, 42332, 23443, 17645], dtype=&#39;int64&#39;, name=&#39;id&#39;)<br>===================================================================================<br>Info : Column name, Non-null count, Datatype --&gt;<br>&lt;class &#39;pandas.core.frame.DataFrame&#39;&gt;<br>Index: 5 entries, 12123 to 17645<br>Data columns (total 6 columns):<br> #   Column         Non-Null Count  Dtype  <br>---  ------         --------------  -----  <br> 0   Make           5 non-null      object <br> 1   Model          5 non-null      object <br> 2   Year           5 non-null      int64  <br> 3   Fuel_Type      5 non-null      object <br> 4   Mileage(kmpl)  4 non-null      float64<br> 5   Price(USD)     5 non-null      int64  <br>dtypes: float64(1), int64(2), object(3)<br>memory usage: 280.0+ bytes<br>None<br>===================================================================================<br>Datatypes of the columns in a DataFrame --&gt;<br> Make              object<br>Model             object<br>Year               int64<br>Fuel_Type         object<br>Mileage(kmpl)    float64<br>Price(USD)         int64<br>dtype: object<br>===================================================================================</pre><h3>Accessing Columns in a DataFrame</h3><p>Once your DataFrame is ready, you’ll often need to select specific columns — and Pandas gives you multiple ways to do that.</p><ul><li>You can select multiple columns by passing a list of column names inside <strong>double brackets</strong>. For example, [[&#39;Make&#39;, &#39;Model&#39;]] pulls just those two columns.</li><li>For <strong>individual columns</strong>, you can either use square brackets like df[&#39;Make&#39;] or the shorter <strong>dot notation</strong> like df.Make. Both work the same (though dot notation won’t work if the column <strong>name has spaces or special characters</strong>).</li><li>If you want to select columns by position, use .iloc. For example, df.iloc[:, 0:2] grabs the <strong>first two columns</strong> (all rows, columns from 0 up to 2).</li><li>You can also use slicing on column names — df[df.columns[1:4]] lets you grab a <strong>range of column labels</strong> dynamically.</li><li>Want only the <strong>numeric columns</strong>? Use .select_dtypes(include=&#39;number&#39;) to filter just those.</li><li>And if you want to find column names that <strong>contain a certain keyword or character</strong>, use .filter(like=&#39;M&#39;). This will return all columns with an &#39;M&#39; in their name — super useful for quick filtering!</li></ul><p>These techniques are really helpful when exploring or working with large datasets where column selection matters.</p><pre># ===================================================================================<br># Accessing columns : by columnname, by slicing, iloc, . notation, filter, by datatype<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Selecting multiple specific columns using double brackets [&#39;Make&#39;,&#39;Model&#39;] --&gt;&quot;)<br>print(car_data_csv[[&#39;Make&#39;,&#39;Model&#39;]])<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Accessing individual columns using dot notation --&gt;&quot;)<br>print(&quot;Make column:\n&quot;, car_data_csv.Make)<br>print(&quot;Model column:\n&quot;, car_data_csv.Model)<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Selecting first two columns using iloc (position-based indexing) --&gt;&quot;)<br>print(car_data_csv.iloc[:, 0:2])<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Selecting a range of columns using slicing on column names [1:4] --&gt;&quot;)<br>print(car_data_csv[car_data_csv.columns[1:4]])<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Selecting only numeric columns using select_dtypes(include=&#39;number&#39;) --&gt;&quot;)<br>print(car_data_csv.select_dtypes(include=&#39;number&#39;))<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Filtering columns whose names contain the letter &#39;M&#39; using filter(like=&#39;M&#39;) --&gt;&quot;)<br>print(car_data_csv.filter(like=&#39;M&#39;))<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Selecting multiple specific columns using double brackets [&#39;Make&#39;,&#39;Model&#39;] --&gt;<br>         Make     Model<br>id                     <br>12123  Toyota   Corolla<br>31212   Honda     Civic<br>42332    Ford     F-150<br>23443   Tesla   Model 3<br>17645     BMW  3 Series<br>===================================================================================<br>Accessing individual columns using dot notation --&gt;<br>Make column:<br> id<br>12123    Toyota<br>31212     Honda<br>42332      Ford<br>23443     Tesla<br>17645       BMW<br>Name: Make, dtype: object<br>Model column:<br> id<br>12123     Corolla<br>31212       Civic<br>42332       F-150<br>23443     Model 3<br>17645    3 Series<br>Name: Model, dtype: object<br>===================================================================================<br>Selecting first two columns using iloc (position-based indexing) --&gt;<br>         Make     Model<br>id                     <br>12123  Toyota   Corolla<br>31212   Honda     Civic<br>42332    Ford     F-150<br>23443   Tesla   Model 3<br>17645     BMW  3 Series<br>===================================================================================<br>Selecting a range of columns using slicing on column names [1:4] --&gt;<br>          Model  Year Fuel_Type<br>id                             <br>12123   Corolla  2020    Petrol<br>31212     Civic  2019    Petrol<br>42332     F-150  2018    Diesel<br>23443   Model 3  2021  Electric<br>17645  3 Series  2020    Petrol<br>===================================================================================<br>Selecting only numeric columns using select_dtypes(include=&#39;number&#39;) --&gt;<br>       Year  Mileage(kmpl)  Price(USD)<br>id                                    <br>12123  2020           18.0       18000<br>31212  2019           17.5       17500<br>42332  2018           12.0       22000<br>23443  2021            NaN       35000<br>17645  2020           15.0       41000<br>===================================================================================<br>Filtering columns whose names contain the letter &#39;M&#39; using filter(like=&#39;M&#39;) --&gt;<br>         Make     Model  Mileage(kmpl)<br>id                                    <br>12123  Toyota   Corolla           18.0<br>31212   Honda     Civic           17.5<br>42332    Ford     F-150           12.0<br>23443   Tesla   Model 3            NaN<br>17645     BMW  3 Series           15.0<br>===================================================================================</pre><h3>Accessing Rows in a DataFrame — Using Indexes, Slices, and Conditions</h3><p>Just like columns, you can access rows in multiple ways depending on what you’re trying to do.</p><ul><li>To fetch rows <strong>by their position</strong>, use .iloc[]. For example, df.iloc[2:5] gives you rows at positions 2, 3, and 4 (remember, the end is exclusive).</li><li>If you’ve set a <strong>custom index</strong> (like an ID), you can use .loc[] to access rows by their actual <strong>label</strong>. For example, df.loc[23443:17645] gives you rows between those two index values.</li><li>Want to filter rows based on a <strong>condition</strong>? You can use a boolean filter like df[df[&#39;Year&#39;] &gt; 2019]. This returns all rows where the &quot;Year&quot; column is greater than 2019.</li><li>Similarly, you can check for <strong>exact matches</strong>, like df[df[&#39;Make&#39;] == &#39;Tesla&#39;] to pull out all rows where the Make is Tesla.</li></ul><p>These methods are super flexible and form the core of how you explore and manipulate data in Pandas.</p><pre># ===================================================================================<br># Accessing rows : by index, slicing, iloc, loc, conditional<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Accessing rows using iloc[2:5] --&gt;&quot;)<br>print(car_data_csv.iloc[2:5]) # car_data_csv.iloc[i-1] for any i th row <br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Accessing rows using DataFrame index  [23443:17645]--&gt;&quot;)<br>print(car_data_csv.loc[23443:17645]) # car_data_csv.iloc[i1:i2] for any rows between indices i1 and i2<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Accessing rows based on condition (Year &gt; 2019) --&gt;&quot;)<br>print(car_data_csv[car_data_csv[&#39;Year&#39;] &gt; 2019])<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Accessing rows with match [&#39;Make&#39;] == &#39;Tesla&#39; --&gt;&quot;)<br>print(car_data_csv[car_data_csv[&#39;Make&#39;] == &#39;Tesla&#39;])<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Accessing rows using iloc[2:5] --&gt;<br>        Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>id                                                               <br>42332   Ford     F-150  2018    Diesel           12.0       22000<br>23443  Tesla   Model 3  2021  Electric            NaN       35000<br>17645    BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================<br>Accessing rows using DataFrame index  [23443:17645]--&gt;<br>        Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>id                                                               <br>23443  Tesla   Model 3  2021  Electric            NaN       35000<br>17645    BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================<br>Accessing rows based on condition (Year &gt; 2019) --&gt;<br>         Make     Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>id                                                                <br>12123  Toyota   Corolla  2020    Petrol           18.0       18000<br>23443   Tesla   Model 3  2021  Electric            NaN       35000<br>17645     BMW  3 Series  2020    Petrol           15.0       41000<br>===================================================================================<br>Accessing rows with match [&#39;Make&#39;] == &#39;Tesla&#39; --&gt;<br>        Make    Model  Year Fuel_Type  Mileage(kmpl)  Price(USD)<br>id                                                              <br>23443  Tesla  Model 3  2021  Electric            NaN       35000<br>===================================================================================</pre><h3>Accessing Specific Rows and Columns Together — Precise and Powerful</h3><p>Now that you’re comfortable accessing rows and columns separately, let’s combine them! Pandas lets you access <strong>specific parts of the DataFrame</strong> using both row and column indexes — with either .iloc or .loc.</p><ul><li><strong>.iloc[] is position-based</strong>, meaning it works with integer indexes.</li><li>Example: df.iloc[1:4, 0:3] gives rows 1 to 3 and columns 0 to 2.</li><li>You can also use lists to pick specific rows/columns like df.iloc[[0, 2], [1, 4]].</li><li><strong>.loc[] is label-based</strong>, meaning it uses the actual row/column names or custom index labels.</li><li>Example: df.loc[31212:42332, &#39;Make&#39;:&#39;Year&#39;] slices rows and columns by label.</li><li>You can also fetch specific combinations like df.loc[[12123, 23443], [&#39;Model&#39;, &#39;Price(USD)&#39;]].</li><li>You can use <strong>conditions</strong> too! For instance, filter all cars with &#39;Petrol&#39; fuel type and only fetch &#39;Make&#39; and &#39;Price&#39; columns using: df.loc[df[&#39;Fuel_Type&#39;] == &#39;Petrol&#39;, [&#39;Make&#39;, &#39;Price(USD)&#39;]]</li></ul><h4>Fast Element Access with .at[] and .iat[]</h4><ul><li>Use .at[index, column] for fast access to a single value by <strong>label</strong> (great for performance).</li><li>Use .iat[row_idx, col_idx] for the same but by <strong>position</strong> (zero-based integers).</li></ul><p>These tools give you <strong>fine-grained control</strong> over your data — whether you’re selecting ranges or just a single value.</p><pre># ===================================================================================<br># Accessing both Rows and Columns (together): iloc, loc, slicing, conditional<br># ===================================================================================<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Using iloc - Row 1 to 3, Columns 0 to 2 --&gt;&quot;)<br>print(car_data_csv.iloc[1:4, 0:3])  # rows 1 to 3 (exclusive), cols 0 to 2 (exclusive)<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Using loc - Rows with index 31212 to 42332, Columns &#39;Make&#39; to &#39;Year&#39; --&gt;&quot;)<br>print(car_data_csv.loc[31212:42332, &#39;Make&#39;:&#39;Year&#39;])  # label-based slicing<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Using iloc - Selecting specific rows and columns --&gt;&quot;) # just specific - not range<br>print(car_data_csv.iloc[[0, 2], [1, 4]])  # 0th &amp; 2nd row, 1st &amp; 4th column<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Using loc - Selecting specific rows and column names --&gt;&quot;)<br>print(car_data_csv.loc[[12123, 23443], [&#39;Model&#39;, &#39;Price(USD)&#39;]])<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Using condition (Fuel_Type == &#39;Petrol&#39;) and selecting &#39;Make&#39;, &#39;Price(USD)&#39; --&gt;&quot;)<br>print(car_data_csv.loc[car_data_csv[&#39;Fuel_Type&#39;] == &#39;Petrol&#39;, [&#39;Make&#39;, &#39;Price(USD)&#39;]])<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Using at[] for fast scalar access [index, column] --&gt;&quot;)<br>print(&quot;Price of car with index 17645:&quot;, car_data_csv.at[17645, &#39;Price(USD)&#39;]) # row index, column name<br>print(&quot;===================================================================================&quot;)<br><br>print(&quot;Using iat[] for fast scalar access by position [row_idx, col_idx] --&gt;&quot;)<br>print(&quot;Element at row 2, column 3:&quot;, car_data_csv.iat[2, 3]) # integer <br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Using iloc - Row 1 to 3, Columns 0 to 2 --&gt;<br>        Make    Model  Year<br>id                         <br>31212  Honda    Civic  2019<br>42332   Ford    F-150  2018<br>23443  Tesla  Model 3  2021<br>===================================================================================<br>Using loc - Rows with index 31212 to 42332, Columns &#39;Make&#39; to &#39;Year&#39; --&gt;<br>        Make  Model  Year<br>id                       <br>31212  Honda  Civic  2019<br>42332   Ford  F-150  2018<br>===================================================================================<br>Using iloc - Selecting specific rows and columns --&gt;<br>         Model  Mileage(kmpl)<br>id                           <br>12123  Corolla           18.0<br>42332    F-150           12.0<br>===================================================================================<br>Using loc - Selecting specific rows and column names --&gt;<br>         Model  Price(USD)<br>id                        <br>12123  Corolla       18000<br>23443  Model 3       35000<br>===================================================================================<br>Using condition (Fuel_Type == &#39;Petrol&#39;) and selecting &#39;Make&#39;, &#39;Price(USD)&#39; --&gt;<br>         Make  Price(USD)<br>id                       <br>12123  Toyota       18000<br>31212   Honda       17500<br>17645     BMW       41000<br>===================================================================================<br>Using at[] for fast scalar access [index, column] --&gt;<br>Price of car with index 17645: 41000<br>===================================================================================<br>Using iat[] for fast scalar access by position [row_idx, col_idx] --&gt;<br>Element at row 2, column 3: Diesel<br>===================================================================================</pre><h3>Wrapping Up — What We’ve Learned So Far</h3><p>Congratulations on making it this far! 🙌</p><p>In this part of the Pandas blog, we explored a solid foundation of what Pandas can do — especially with <strong>Series</strong> and <strong>DataFrames</strong>. We looked at:</p><ul><li>Creating Pandas Series from different data sources like NumPy arrays, dictionaries, and scalars</li><li>Understanding important Series properties (shape, size, data types, null checks, etc.)</li><li>Accessing, transforming, and sorting Series data</li><li>Performing basic analysis using functions like describe(), sum(), max(), and unique()</li><li>Creating DataFrames from dictionaries, lists, and CSV files</li><li>Setting custom indexes and renaming columns</li><li>Accessing rows and columns in multiple ways — including conditions, slicing, and label-based access</li></ul><p>We covered <strong>a lot</strong> — and this is just scratching the surface!<br>Pandas has way more power waiting for you, and we’re going to explore it all step-by-step.</p><p>In the next part of this blog series, we’ll dive into more advanced and practical things:</p><ul><li>Filtering and querying data</li><li>Handling missing values (NaN)</li><li>Merging, joining, and concatenating DataFrames</li><li>Working with groupby, aggregation, and pivot tables</li><li>DateTime operations, exporting data, and more!</li></ul><p>Thank you for following along! If you found this helpful, stay tuned for Part 2 — it’s going to be even more fun and practical.</p><p>Let me know in the comments if there’s anything.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bd938a0c7a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Welcome to NumPy — Your First Step Toward Data Science with Python]]></title>
            <link>https://medium.com/@rakeshreddyn7/welcome-to-numpy-your-first-step-toward-data-science-with-python-005507d89cb7?source=rss-2fb26e12c93f------2</link>
            <guid isPermaLink="false">https://medium.com/p/005507d89cb7</guid>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Rakesh Reddy Nallagondla]]></dc:creator>
            <pubDate>Wed, 02 Apr 2025 21:29:59 GMT</pubDate>
            <atom:updated>2025-04-02T21:29:59.899Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*qRb9qLtp3pZhEGtd7vYkmw.png" /><figcaption>NumPy — The backbone of numerical computing in Python</figcaption></figure><h3>Welcome to NumPy — Your First Step Toward Data Science with Python</h3><p>If you’re just getting started with <strong>Data Science</strong>, <strong>Machine Learning</strong>, or even just curious about Python’s capabilities with numbers, then <strong>NumPy</strong> is the perfect place to begin.<br>In this blog, we’ll break down <strong>NumPy (Numerical Python)</strong> in the most beginner-friendly way possible. Whether you’re a student, a data science aspirant, or a developer wanting to explore scientific computing, this guide will help you understand and start using NumPy confidently.</p><h3>What You’ll Learn</h3><p>By the end of this blog, you’ll be able to:</p><ul><li>Understand what <strong>NumPy</strong> is and why it’s so important</li><li>See how NumPy compares with native <strong>Python lists</strong></li><li>Create and manipulate <strong>1D and 2D arrays</strong></li><li>Perform <strong>fast mathematical and statistical operations</strong></li><li>Work with <strong>random number generation</strong> and <strong>array reshaping</strong></li><li>Explore useful functions like np.sort(), np.where(), np.unique(), and more</li><li>Perform <strong>bitwise</strong>, <strong>logical</strong>, and even <strong>string operations</strong> using NumPy</li></ul><h3>What We’ll Explore (Step by Step)</h3><p>We’ll go step-by-step from basics to advanced everyday functions:</p><ul><li>A little background on <strong>NumPy</strong></li><li>Performance comparison with <strong>Python lists</strong></li><li>Array <strong>creation</strong> and <strong>reshaping</strong></li><li><strong>Indexing and slicing</strong> like pros!</li><li><strong>Arithmetic and statistical</strong> operations</li><li><strong>Random number</strong> generation</li><li>Useful array methods (unique, where, any, etc.)</li><li><strong>Bitwise</strong> and <strong>logical</strong> operations</li><li><strong>String handling</strong> with np.char</li></ul><p><strong>No prior experience needed</strong> — just some curiosity and basic Python knowledge.<br>I’ve packed this blog with <strong>real examples</strong>, <strong>detailed outputs</strong>, and <strong>simple explanations</strong>.</p><p><strong>Note:</strong> As you go through the code examples in this blog, don’t skip over the comments and print statements. They’re not just there for show — they hold important explanations, key takeaways, and real insights that’ll help you actually understand what’s going on. Most of the learning here is tucked inside those small notes!</p><p>Let’s get started!</p><p>NumPy (Numerical Python) was created by <strong>Travis Oliphant</strong> in 2005 by improving below older libararies.</p><p><strong>matrix-sig:</strong> In 1995 the special interest group (SIG) matrix-sig was founded with the aim of defining an array computing package.</p><p><strong>Numeric:</strong> In 1990s Numeric was the first numerical computing package, developed by <em>Jim Fulton</em> and later improved by <em>Jim Hugunin</em>.</p><p><strong>Numarray:</strong> Introduced as a more flexible replacement for Numeric in 2005, it was faster for large arrays but slower for small ones.</p><p><strong>NumPy:</strong> In 2005, <strong>Travis Oliphant</strong> unified the features of Numeric and Numarray to create NumPy, releasing version 1.0 in 2006. Initially part of <em>SciPy</em>, it became a standalone package to avoid requiring SciPy for just array operations.</p><p>Available Since: Python 2.4+ (now fully compatible with Python 3)</p><h4>Why Do We Need NumPy?</h4><p>Python has built-in lists — so why do we need to learn NumPy?</p><p>The answer is simple: <em>Speed, Efficiency, and Power</em>.</p><p>When working with large amounts of data or performing mathematical operations, Python lists become slow and memory-hungry. NumPy solves this by offering faster, memory-efficient arrays and a wide range of tools for numerical computing.</p><h4>What Can We Do with NumPy?</h4><ol><li>Perform mathematical operations quickly (add, subtract, multiply arrays without loops).</li><li>Handle large datasets using less memory.</li><li>Work with multi-dimensional arrays (2D, 3D, and more).</li><li>Use powerful built-in functions for statistics, linear algebra, and reshaping data.</li><li>Perform vectorized operations — apply operations to entire arrays at once.</li></ol><h4>Libraries Built on Top of NumPy</h4><p>NumPy is the foundation of many popular libraries:</p><p><strong>-Pandas</strong> — Data analysis and manipulation.<br>-<strong>TensorFlow &amp; PyTorch</strong> — Deep learning frameworks.<br>-<strong>SciPy</strong> — Scientific computing.<br>-<strong>Scikit-learn</strong> — Machine learning.<br>-<strong>OpenCV</strong> — Image and video processing.<br>If you’re using any of these libraries, you’re already using NumPy behind the scenes!</p><p>Now that we understand why NumPy is essential, let’s dive into some real examples to see how it works and why it’s so powerful. We’ll explore array creation, operations, and useful functions step by step.</p><h4>Importing NumPy</h4><p>Before we start working with NumPy, we need to <strong>import</strong> it into our Python environment. The most common convention is to import it as <strong>np</strong>, which makes it easier to use (and saves typing!). We can also check some basic information about the module after importing it:</p><p>np.__name__ tells you the module name — helpful to confirm what you imported.</p><p>help(np) opens a detailed docstring showing available functions and usage.</p><p>np.__doc__ gives a quick one-line description of what NumPy is.</p><p>np.show_config() shows build info like BLAS/LAPACK settings — useful for performance tuning and debugging.</p><pre>import numpy as np<br>print(np.__name__) # Check the Name of the Imported Module<br># print(help(np)) # You can access NumPy documentation<br># print(np.__doc__) # Short description about the package<br># print(np.show_config()) # You can view the build and configuration details of your NumPy installation</pre><pre>numpy</pre><h4>Quick Tip: Get Function Descriptions</h4><p>To get a short description of any NumPy function, you can use below methods.</p><p>For more detailed documentation, visit: <a href="https://numpy.org/doc/">https://numpy.org/doc/</a></p><pre># Quick info inside Jupyter<br># np.mean?<br># Short and clean description<br># help(np.median)</pre><h4>Python List vs NumPy Array</h4><p>Let’s understand how NumPy arrays are different from Python lists with simple examples.</p><p>You don’t need to worry about the functions used in below code — this is just to show the difference in <strong>how fast NumPy arrays and Python lists perform the same task</strong>. Just take a look at the result.</p><p>NumPy completed the sum operation in just <strong>microseconds</strong>, while Python list took <strong>milliseconds</strong>.</p><pre>import numpy as np<br># Create large Python list and NumPy array<br>py_list = list(range(1000000))<br>np_array = np.array(py_list)<br># Time taken for sum operation<br>%timeit np.sum(np_array)   # NumPy array sum<br>%timeit sum(py_list)       # Python list sum</pre><pre>562 μs ± 20.6 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)<br>12.7 ms ± 212 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)</pre><h4>How NumPy array is different from Python list</h4><p>Let’s explore a <strong>key difference between Python lists and NumPy arrays</strong> — how they handle different data types.</p><p>In this example:</p><ul><li>We create a regular Python list with a mix of characters and numbers.</li><li>Then, we create a NumPy array using the same elements.</li></ul><p><strong>Observation</strong>:</p><ul><li>Python lists are flexible — they allow different types of data (like &#39;H&#39;, 2, &#39;5&#39;) to coexist.</li><li>NumPy arrays, on the other hand, require all elements to be of the <strong>same type</strong>. So NumPy automatically <strong>converts everything into strings</strong> in this case.</li></ul><p>This behavior is important because NumPy is built for performance — and keeping all data in the same type helps it run faster and more efficiently.</p><pre>print(&quot;===================================================================================&quot;)<br>py_list = [&#39;H&#39;, &#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;, 1, 2, 3, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;]<br>print(&quot;TYPE OF py_list --&gt;&quot;,type(py_list))<br>print(&quot;Element at index 0 is &#39;{}&#39; and it&#39;s type is &#39;{}&#39;&#39;&quot;.format(py_list[0],type(py_list[0])))<br>print(&quot;Element at index 6 is &#39;{}&#39; and it&#39;s type is &#39;{}&#39;&#39;&quot;.format(py_list[6],type(py_list[6])))<br>print(&quot;PYTHON LIST --&gt;&quot;,py_list)<br>print(&quot;===================================================================================&quot;)<br>np_array = np.array([&#39;H&#39;, &#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;, 1, 2, 3, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;])<br>print(&quot;TYPE OF np_array --&gt; &quot;, type(np_array))<br>print(&quot;NUMPY ARRAY --&gt; &quot;,np_array)<br>print(&quot;Element at index 0 is &#39;{}&#39; and it&#39;s type is &#39;{}&#39;&#39;&quot;.format(np_array[0],type(np_array[0])))<br>print(&quot;Element at index 6 is &#39;{}&#39; and it&#39;s type is &#39;{}&#39;&#39;&quot;.format(np_array[6],type(np_array[6])))<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>TYPE OF py_list --&gt; &lt;class &#39;list&#39;&gt;<br>Element at index 0 is &#39;H&#39; and it&#39;s type is &#39;&lt;class &#39;str&#39;&gt;&#39;&#39;<br>Element at index 6 is &#39;2&#39; and it&#39;s type is &#39;&lt;class &#39;int&#39;&gt;&#39;&#39;<br>PYTHON LIST --&gt; [&#39;H&#39;, &#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;, 1, 2, 3, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;]<br>===================================================================================<br>TYPE OF np_array --&gt;  &lt;class &#39;numpy.ndarray&#39;&gt;<br>NUMPY ARRAY --&gt;  [&#39;H&#39; &#39;e&#39; &#39;l&#39; &#39;l&#39; &#39;o&#39; &#39;1&#39; &#39;2&#39; &#39;3&#39; &#39;4&#39; &#39;5&#39; &#39;6&#39;]<br>Element at index 0 is &#39;H&#39; and it&#39;s type is &#39;&lt;class &#39;numpy.str_&#39;&gt;&#39;&#39;<br>Element at index 6 is &#39;2&#39; and it&#39;s type is &#39;&lt;class &#39;numpy.str_&#39;&gt;&#39;&#39;<br>===================================================================================</pre><h4>Python List vs NumPy Array — Operator Comparison</h4><p>Although Python lists and NumPy arrays may look similar, they behave <strong>very differently</strong> when it comes to operations like comparisons, arithmetic, and broadcasting.</p><p>Here’s what you’ll observe in this section:</p><ul><li>Python lists are <strong>flexible</strong> but don’t support element-wise operations directly (like +3 or &gt;3). These will result in errors.</li><li>NumPy arrays are <strong>powerful</strong> when it comes to numeric operations — you can perform comparisons, additions, multiplications, etc., and they apply automatically to each element (this is called <em>vectorization</em>).</li><li>Lists use + for <strong>concatenation</strong>, while NumPy arrays use + for <strong>element-wise addition</strong>.</li><li>Similarly, multiplying a list by 3 repeats the list, while multiplying a <strong>NumPy array by 3 multiplies each value by 3</strong>.</li><li>Division is <strong>not supported</strong> for lists but works seamlessly with NumPy arrays.</li></ul><p>This makes NumPy a much better choice when dealing with <strong>mathematical and scientific computations</strong>, especially with large datasets.</p><pre>py_list = list(range(1,6))<br>np_array = np.array(range(1,6))<br>print(&quot;===================================================================================&quot;)<br>print(&quot;py_list --&gt;&quot;, py_list) # [1, 2, 3, 4, 5]<br>print(&quot;np_array --&gt;&quot;, np_array) # [1 2 3 4 5]<br>print(&quot;TYPE OF py_list&quot;, type(py_list), &quot;and TYPE OF np_array&quot;, type(np_array)) # &lt;class &#39;list&#39;&gt;, &lt;class &#39;numpy.ndarray&#39;&gt;<br>print(&quot;===================================================================================&quot;)<br>### Comparison Operators : &lt;, &gt;, ==, !=<br>print(&quot;py_list &gt; 3 --&gt; Error&quot;) # Python lists do not support element-wise comparison like &gt; 3. It raises an error.<br>print(&quot;Np_array &gt; 3 --&gt;&quot;, np_array&gt;3) # NumPy arrays apply the condition to each element and return [False False False True True]<br>print(&quot;py_list == py_list --&gt;&quot;, py_list==py_list) # Lists return a single True/False based on overall equality. True<br>print(&quot;Np_array == Np_array --&gt;&quot;, np_array==np_array) # NumPy arrays return element-wise comparison. [ True  True  True  True  True]<br>print(&quot;===================================================================================&quot;)<br>### Arithmetic Operators<br>print(&quot;py_list + py_list --&gt;&quot;, py_list+py_list) # Python List &#39;+&#39; joins the list: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]<br>print(&quot;Np_array + Np_array --&gt;&quot;, np_array+np_array) # NumPy Array &#39;+&#39; adds numbers: [ 2  4  6  8 10]<br>print(&quot;py_list + 3 --&gt; Error&quot;) # Error<br>print(&quot;Np_array + 3&quot;, np_array+3) # NumPy arrays can add a single number to all elements: [4 5 6 7 8]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;py_list * py_list --&gt; Error&quot;) # Error<br>print(&quot;Np_array * Np_array --&gt;&quot;, np_array*np_array) # NumPy Array * NumPy Array → element-wise multiplication. [ 1  4  9 16 25]<br>print(&quot;py_list * 3 --&gt;&quot;, py_list*3) # Python List * 3 → repeats list 3 times. [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]<br>print(&quot;Np_array * 3 --&gt; &quot;, np_array*3) # NumPy Array * 3 → multiplies each element by 3. [ 3  6  9 12 15]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;py_list / py_list --&gt; Error&quot;) # Error<br>print(&quot;Np_array / Np_array --&gt; &quot;,np_array/np_array) # Numpy Array / NumPy Array = [1. 1. 1. 1. 1.]<br>print(&quot;py_list / 3 --&gt; Error&quot;) # Error<br>print(&quot;Np_array / 3 --&gt; &quot;,np_array/3) # NumPy arrays divide each element by 3: [0.33333333 0.66666667 1.         1.33333333 1.66666667]<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>py_list --&gt; [1, 2, 3, 4, 5]<br>np_array --&gt; [1 2 3 4 5]<br>TYPE OF py_list &lt;class &#39;list&#39;&gt; and TYPE OF np_array &lt;class &#39;numpy.ndarray&#39;&gt;<br>===================================================================================<br>py_list &gt; 3 --&gt; Error<br>Np_array &gt; 3 --&gt; [False False False  True  True]<br>py_list == py_list --&gt; True<br>Np_array == Np_array --&gt; [ True  True  True  True  True]<br>===================================================================================<br>py_list + py_list --&gt; [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]<br>Np_array + Np_array --&gt; [ 2  4  6  8 10]<br>py_list + 3 --&gt; Error<br>Np_array + 3 [4 5 6 7 8]<br>===================================================================================<br>py_list * py_list --&gt; Error<br>Np_array * Np_array --&gt; [ 1  4  9 16 25]<br>py_list * 3 --&gt; [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]<br>Np_array * 3 --&gt;  [ 3  6  9 12 15]<br>===================================================================================<br>py_list / py_list --&gt; Error<br>Np_array / Np_array --&gt;  [1. 1. 1. 1. 1.]<br>py_list / 3 --&gt; Error<br>Np_array / 3 --&gt;  [0.33333333 0.66666667 1.         1.33333333 1.66666667]<br>===================================================================================</pre><h4>Indexing and Slicing in NumPy</h4><p>Just like Python lists, NumPy arrays allow you to <strong>access elements by index</strong> — but with more power and flexibility. In this section, we’ll explore how to extract values, ranges, and patterns from arrays using indexing and slicing techniques.</p><p>Here’s what you can do:</p><ul><li>Access any <strong>element by position</strong>, using positive or negative indices.</li><li>Extract a <strong>range of elements</strong> using slicing — just like Python (array[start:stop]).</li><li>Use <strong>negative indices</strong> to count from the end of the array.</li><li>Use slicing with <strong>steps</strong> to skip values (array[::2]) or <strong>reverse</strong> an array (array[::-1]).</li></ul><p>These operations are super handy for tasks like feature selection, data filtering, and reshaping datasets before processing them.</p><pre>np_array = np.array([10, 20, 30, 40, 50])<br>print(&quot;===================================================================================&quot;)<br>print(&quot;NUMPY ARRAY --&gt;&quot;, np_array)  # [10 20 30 40 50]<br>print(&quot;Element at index 2 --&gt;&quot;, np_array[2])  # Third element: 30 (indices from beginning 0, 1, 2, 3, 4)<br>print(&quot;Element at index 3 --&gt;&quot;, np_array[-3])  # Third element from end: 30 (indices from end -5, -4, -3, -2, -1)<br>print(&quot;Elements from index 1 to 3 --&gt;&quot;, np_array[1:4])  # [20 30 40] (index 4 excluded)<br>print(&quot;First 3 elements --&gt;&quot;, np_array[:3])  # [10 20 30]<br>print(&quot;First 3 elements by negative index --&gt;&quot;, np_array[:-2]) # [10 20 30] (by negative index)<br>print(&quot;Last 2 elements --&gt;&quot;, np_array[3:]) # [40 50]<br>print(&quot;Last 2 elements by negative index --&gt;&quot;, np_array[-2:])  # [40 50] (by negative index)<br>print(&quot;All Elements --&gt;&quot;, np_array[:])  # [10 20 30 40 50]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Elements with step 2 --&gt;&quot;, np_array[::2])  # [10 30 50]<br>print(&quot;Elements with step 2 in reverse order --&gt;&quot;, np_array[::-2]) # [50 30 10] (in reverse order)<br>print(&quot;Array in reverse --&gt;&quot;, np_array[::-1])  # [50 40 30 20 10]<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>NUMPY ARRAY --&gt; [10 20 30 40 50]<br>Element at index 2 --&gt; 30<br>Element at index 3 --&gt; 30<br>Elements from index 1 to 3 --&gt; [20 30 40]<br>First 3 elements --&gt; [10 20 30]<br>First 3 elements by negative index --&gt; [10 20 30]<br>Last 2 elements --&gt; [40 50]<br>Last 2 elements by negative index --&gt; [40 50]<br>All Elements --&gt; [10 20 30 40 50]<br>===================================================================================<br>Elements with step 2 --&gt; [10 30 50]<br>Elements with step 2 in reverse order --&gt; [50 30 10]<br>Array in reverse --&gt; [50 40 30 20 10]<br>===================================================================================</pre><h4>Understanding 2D Arrays in NumPy</h4><p>In this section, let’s work with 2D arrays, which are like tables with rows and columns. We’ll start by creating a 2D NumPy array and check:</p><ul><li><strong>How many rows and columns</strong> it has?</li><li>What <strong>type of data</strong> it stores?</li><li>How to <strong>access specific elements, rows, or columns</strong>?</li></ul><p>Then, we’ll also see how to:</p><ul><li>Create a <strong>2D array</strong> using two normal Python lists.</li><li>Perform <strong>math operations between two 2D arrays</strong> (like addition and multiplication).</li><li><strong>Reshape</strong> a 1D array into a 2D array (for organizing data better).</li></ul><pre>np_array_2d = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])<br>print(&quot;===================================================================================&quot;)<br>print(&quot;TYPE OF np_array_2d --&gt;&quot;, type(np_array_2d))  # &lt;class &#39;numpy.ndarray&#39;&gt;<br>print(&quot;2D NUMPY ARRAY --&gt; \n&quot;, np_array_2d)  # 2D array (matrix)<br>print(&quot;Shape of np_array_2d --&gt;&quot;, np_array_2d.shape)  # (2, 5) → 2 rows, 5 columns<br>print(&quot;Dimension of np_array_2d --&gt;&quot;, np_array_2d.ndim)  # 2 → it&#39;s a 2D array<br>print(&quot;Total Elements --&gt;&quot;, np_array_2d.size) # 10 elements<br>print(&quot;Data Type --&gt;&quot;, np_array_2d.dtype) # int32 data type<br>print(&quot;Item Size (bytes) --&gt;&quot;, np_array_2d.itemsize) # Usually 4 bytes for int32<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Element at row 0, column 2 using [0][2] --&gt;&quot;, np_array_2d[0][2])  # 3<br>print(&quot;Element at row 0, column 2 using [0,2] --&gt;&quot;, np_array_2d[0,2])  # 3<br>print(&quot;All rows, column 3 --&gt;&quot;, np_array_2d[:,3])  # [4 9]<br>print(&quot;All rows, columns 2 to 3 --&gt;\n&quot;, np_array_2d[:,2:4])  # [[3 4] [8 9]]<br>print(&quot;First row --&gt;&quot;, np_array_2d[0])  # [1 2 3 4 5]<br>print(&quot;Second column --&gt;&quot;, np_array_2d[:,1])  # [2 7]<br>print(&quot;===================================================================================&quot;)<br>### Creating a 2D Array from Two 1D Lists<br>list1 = [1, 2, 3, 4, 5]<br>list2 = [6, 7, 8, 9, 10]<br>np_array_from_lists = np.array([list1, list2])<br>print(&quot;2D NUMPY ARRAY FROM TWO LISTS --&gt;\n&quot;, np_array_from_lists)  # Same as np_array_2d<br>print(&quot;Shape --&gt;&quot;, np_array_from_lists.shape)  # (2, 5)<br>print(&quot;===================================================================================&quot;)<br>### 2D Array Arithmetic Operations<br>np_array1 = np.array([[1, 2, 3], [4, 5, 6]])<br>np_array2 = np.array([[6, 7, 8], [9, 10, 11]])<br>print(&quot;ARRAY 1 --&gt;\n&quot;, np_array1)<br>print(&quot;ARRAY 2 --&gt;\n&quot;, np_array2)<br>print(&quot;Addition --&gt;\n&quot;, np_array1 + np_array2)  # Element-wise addition<br>print(&quot;Multiplication --&gt;\n&quot;, np_array1 * np_array2)  # Element-wise multiplication<br>print(&quot;Array 1 * 2 --&gt;\n&quot;, np_array1 * 2)  # Scalar multiplication<br>print(&quot;===================================================================================&quot;)<br>### Reshape 1D Array to 2D Array<br>np_array_1d = np.array([1, 2, 3, 4, 5, 6])<br>print(&quot;1D ARRAY --&gt;&quot;, np_array_1d)<br>np_array_reshaped = np_array_1d.reshape(2, 3) <br>print(&quot;RESHAPED TO 2D (2x3) --&gt;\n&quot;, np_array_reshaped)<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>TYPE OF np_array_2d --&gt; &lt;class &#39;numpy.ndarray&#39;&gt;<br>2D NUMPY ARRAY --&gt; <br> [[ 1  2  3  4  5]<br> [ 6  7  8  9 10]]<br>Shape of np_array_2d --&gt; (2, 5)<br>Dimension of np_array_2d --&gt; 2<br>Total Elements --&gt; 10<br>Data Type --&gt; int32<br>Item Size (bytes) --&gt; 4<br>===================================================================================<br>Element at row 0, column 2 using [0][2] --&gt; 3<br>Element at row 0, column 2 using [0,2] --&gt; 3<br>All rows, column 3 --&gt; [4 9]<br>All rows, columns 2 to 3 --&gt;<br> [[3 4]<br> [8 9]]<br>First row --&gt; [1 2 3 4 5]<br>Second column --&gt; [2 7]<br>===================================================================================<br>2D NUMPY ARRAY FROM TWO LISTS --&gt;<br> [[ 1  2  3  4  5]<br> [ 6  7  8  9 10]]<br>Shape --&gt; (2, 5)<br>===================================================================================<br>ARRAY 1 --&gt;<br> [[1 2 3]<br> [4 5 6]]<br>ARRAY 2 --&gt;<br> [[ 6  7  8]<br> [ 9 10 11]]<br>Addition --&gt;<br> [[ 7  9 11]<br> [13 15 17]]<br>Multiplication --&gt;<br> [[ 6 14 24]<br> [36 50 66]]<br>Array 1 * 2 --&gt;<br> [[ 2  4  6]<br> [ 8 10 12]]<br>===================================================================================<br>1D ARRAY --&gt; [1 2 3 4 5 6]<br>RESHAPED TO 2D (2x3) --&gt;<br> [[1 2 3]<br> [4 5 6]]<br>===================================================================================</pre><h4>Creating Arrays in NumPy</h4><p>Before diving into complex data operations, it’s important to know how to <strong>create arrays</strong> in NumPy. Whether you’re building test datasets, initializing values, or creating fixed-size arrays, NumPy gives you easy ways to do it.</p><p>Here’s a breakdown of some <strong>commonly used array creation functions</strong>:</p><ul><li>np.arange() creates arrays with a <strong>range of values</strong>, just like Python&#39;s range(), but as a NumPy array.</li><li>np.linspace() generates arrays with a <strong>specific number of evenly spaced values</strong> between two points.</li><li>np.zeros() creates arrays filled entirely with <strong>0s</strong>. You can choose any shape — 1D, 2D, etc.</li><li>np.ones() works the same way but fills the array with <strong>1s</strong> instead.</li><li>np.full() lets you create arrays of any shape, filled with a <strong>value you choose</strong> (e.g., all 7s).</li><li>np.eye() and np.identity() are used to create <strong>identity matrices</strong> (matrices with 1s on the diagonal and 0s elsewhere), which are very useful in linear algebra.</li></ul><p>These tools are super useful when initializing arrays before filling them with actual data or performing operations like matrix multiplication.</p><pre>print(&quot;===================================================================================&quot;) <br>print(&quot;1D array from 0 to 19 --&gt;&quot;, np.arange(0,20)) # [0-19]<br>print(&quot;Array from 0 to 20 with step size 10 --&gt;&quot;, np.arange(0,21,10)) # [0, 10, 20]<br>print(&quot;Array with 10 values evenly spaced --&gt;&quot;, np.linspace(0,2,5)) # [0.  0.5 1.  1.5 2. ]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;1D array of 5 zeros --&gt;&quot;, np.zeros(5)) # [0. 0. 0. 0. 0.]<br>print(&quot;2D array(2,5) with zeroes --&gt;\n&quot;, np.zeros((2,5))) # [[0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.]]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;1D array of 5 ones --&gt;&quot;, np.ones(5)) # [1. 1. 1. 1. 1.]<br>print(&quot;2D array (2 rows, 5 columns) with ones --&gt;\n&quot;, np.ones((2,5))) # [[1. 1. 1. 1. 1.] [1. 1. 1. 1. 1.]]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;1D array of size 5 filled with value 7 --&gt;&quot;, np.full((5),7)) # [7 7 7 7 7]<br>print(&quot;2D array (2 rows, 5 columns) filled with value 7 --&gt;\n&quot;, np.full((2,5),7)) # [[7 7 7 7 7] [7 7 7 7 7]]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;3x3 identity matrix (1s on the diagonal) --&gt;\n&quot;, np.eye(3)) # [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]]<br>print(&quot;3x5 matrix with 1s on the diagonal --&gt;\n&quot;, np.eye(3,5)) # [[1. 0. 0. 0. 0.] [0. 1. 0. 0. 0.] [0. 0. 1. 0. 0.]]<br>print(&quot;5x5 identity matrix --&gt;\n&quot;, np.eye(5,5)) # [[1. 0. 0. 0. 0.] [0. 1. 0. 0. 0.] [0. 0. 1. 0. 0.] [0. 0. 0. 1. 0.] [0. 0. 0. 0. 1.]]<br>print(&quot;===================================================================================&quot;)<br>print(&quot;3x3 identity matrix using identity() --&gt;\n&quot;, np.identity(3)) #[[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]]<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>1D array from 0 to 19 --&gt; [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19]<br>Array from 0 to 20 with step size 10 --&gt; [ 0 10 20]<br>Array with 10 values evenly spaced --&gt; [0.  0.5 1.  1.5 2. ]<br>===================================================================================<br>1D array of 5 zeros --&gt; [0. 0. 0. 0. 0.]<br>2D array(2,5) with zeroes --&gt;<br> [[0. 0. 0. 0. 0.]<br> [0. 0. 0. 0. 0.]]<br>===================================================================================<br>1D array of 5 ones --&gt; [1. 1. 1. 1. 1.]<br>2D array (2 rows, 5 columns) with ones --&gt;<br> [[1. 1. 1. 1. 1.]<br> [1. 1. 1. 1. 1.]]<br>===================================================================================<br>1D array of size 5 filled with value 7 --&gt; [7 7 7 7 7]<br>2D array (2 rows, 5 columns) filled with value 7 --&gt;<br> [[7 7 7 7 7]<br> [7 7 7 7 7]]<br>===================================================================================<br>3x3 identity matrix (1s on the diagonal) --&gt;<br> [[1. 0. 0.]<br> [0. 1. 0.]<br> [0. 0. 1.]]<br>3x5 matrix with 1s on the diagonal --&gt;<br> [[1. 0. 0. 0. 0.]<br> [0. 1. 0. 0. 0.]<br> [0. 0. 1. 0. 0.]]<br>5x5 identity matrix --&gt;<br> [[1. 0. 0. 0. 0.]<br> [0. 1. 0. 0. 0.]<br> [0. 0. 1. 0. 0.]<br> [0. 0. 0. 1. 0.]<br> [0. 0. 0. 0. 1.]]<br>===================================================================================<br>3x3 identity matrix using identity() --&gt;<br> [[1. 0. 0.]<br> [0. 1. 0.]<br> [0. 0. 1.]]<br>===================================================================================</pre><h4>Generating Random Numbers with NumPy</h4><p>Working with random numbers is super common in data science — whether you’re splitting datasets, initializing weights in machine learning, or just creating mock data for testing.</p><p>NumPy makes this really easy with a variety of random number generation functions.</p><p>Here’s what you can do:</p><ul><li><strong>Generate random float values</strong> using functions like np.random.ranf(), np.random.random(), and np.random.sample(). These return values <strong>between 0 and 1</strong>, either as a single number or as arrays of any shape you need (like 1D or 2D).</li><li><strong>Generate random integers</strong> with np.random.randint(). You can control the range (low, high) and how many values or dimensions you want — 1D arrays, 2D grids, and more.</li><li><strong>Select random elements from a given set</strong> using np.random.choice(). You can: Pick a <strong>single</strong> random value, Create an array of <strong>random choices, </strong>Choose values <strong>without duplication</strong> by setting replace=False, Specify a <strong>custom range</strong> using np.arange()</li></ul><p>These functions are super useful when you’re experimenting or building anything that needs randomness — sampling, or simply testing how your code behaves with unpredictable input.</p><pre>print(&quot;===================================================================================&quot;)<br>print(&quot;Random float (0 to 1) --&gt;&quot;, np.random.ranf())  # Single random float in between 0 to 1<br>print(&quot;1D array of random floats --&gt;&quot;, np.random.ranf(5))  # 1D array of 5 random floats<br>print(&quot;2D array (2x4) of random floats --&gt;\n&quot;, np.random.ranf(size=(2,4)))  # 2D random floats and = np.random.ranf((2,4))<br>print(&quot;===================================================================================&quot;)<br>print(&quot;1D array using random() --&gt;&quot;, np.random.random(5))  # Same as ranf<br>print(&quot;2D array (2x5) using random() --&gt;\n&quot;, np.random.random(size=(2,5))) # 2x5 random floats in 0 to 1<br>print(&quot;===================================================================================&quot;)<br>print(&quot;1D array using sample() --&gt;&quot;, np.random.sample(5))  # Float values [0.0, 1.0)<br>print(&quot;2D array using sample() --&gt;\n&quot;, np.random.sample(size=(2,5))) # 2x5 randome values between 0 and 1<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Random integer from 0 to 4 --&gt;&quot;, np.random.randint(5))  # Single int between 0 to 4(including)<br>print(&quot;1D array of 4 integers (0 to 9) --&gt;&quot;, np.random.randint(0, 10, 4))  # [low, high), size=4<br>print(&quot;2D array (2x4) of random integers (0 to 14) --&gt;\n&quot;, np.random.randint(low=0, high=15, size=(2,4)))#you can just mention by&#39;,&#39;<br>print(&quot;Another way to write 2D array (2x4) --&gt;\n&quot;, np.random.randint(0, 15, (2,4)))  # Equivalent<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Random single choice from 0 to 9 --&gt;&quot;, np.random.choice(10))  # Picks one number from [0,9]<br>print(&quot;Random 1D array of 5 choices from 0 to 9 --&gt;&quot;, np.random.choice(10, size=5))  # with replacement by default<br>print(&quot;Random 3x4 grid from 0 to 12 (no duplicates) --&gt;\n&quot;, np.random.choice(13, size=(3,4), replace=False)) # no duplicates<br>print(&quot;Random 1D array of 5 choices (from 0 to 99, with duplicates allowed) --&gt;&quot;, <br>      np.random.choice(np.arange(0,100), size=5, replace=True)) # you can specify range using np.arange in np.random.choice<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Random float (0 to 1) --&gt; 0.0361203636587778<br>1D array of random floats --&gt; [0.2849354  0.69051057 0.60526404 0.73948553 0.31665146]<br>2D array (2x4) of random floats --&gt;<br> [[0.39541823 0.75893182 0.57134269 0.79773216]<br> [0.14809938 0.62452262 0.47769734 0.81851108]]<br>===================================================================================<br>1D array using random() --&gt; [0.4636192  0.46345915 0.94307211 0.33945676 0.57994363]<br>2D array (2x5) using random() --&gt;<br> [[0.54808233 0.09505075 0.07386208 0.54788902 0.77243847]<br> [0.50324417 0.27594429 0.57880538 0.7881471  0.10901523]]<br>===================================================================================<br>1D array using sample() --&gt; [0.34319045 0.04966946 0.49987692 0.13313009 0.27701237]<br>2D array using sample() --&gt;<br> [[0.18088691 0.4035142  0.91350571 0.26131549 0.29126968]<br> [0.45824179 0.45800613 0.90572913 0.85530769 0.41339403]]<br>===================================================================================<br>Random integer from 0 to 4 --&gt; 1<br>1D array of 4 integers (0 to 9) --&gt; [6 3 1 7]<br>2D array (2x4) of random integers (0 to 14) --&gt;<br> [[11  0  0  3]<br> [ 1  9  0 10]]<br>Another way to write 2D array (2x4) --&gt;<br> [[ 4  0 12  0]<br> [11  6 10  0]]<br>===================================================================================<br>Random single choice from 0 to 9 --&gt; 4<br>Random 1D array of 5 choices from 0 to 9 --&gt; [8 9 6 7 3]<br>Random 3x4 grid from 0 to 12 (no duplicates) --&gt;<br> [[11  7  1  9]<br> [10  3  4  5]<br> [ 6  0  8 12]]<br>Random 1D array of 5 choices (from 0 to 99, with duplicates allowed) --&gt; [38 72 30 79 51]<br>===================================================================================</pre><h4>Mathematical and Statistical Operations using NumPy</h4><ul><li>NumPy gives you powerful tools to do <strong>math and stats</strong> operations directly on arrays — no loops needed.</li><li>You can easily perform addition, multiplication, exponentials, logarithms, trigonometry, and power calculations.</li><li>It also supports <strong>statistical calculations</strong> like mean, median, standard deviation, and correlation — all in one line.</li><li>And when working with conditions, NumPy provides <strong>element-wise operations</strong> like greater, less, and equal for easy comparisons.</li><li>Plus, NumPy even supports <strong>bit-level operations</strong> like AND, NOT, shifting bits, and viewing binary representation.</li><li>All these operations are <strong>vectorized</strong> — meaning they apply to entire arrays at once, making your code fast and clean.</li></ul><pre>print(&quot;===================================================================================&quot;)<br>np_array_1 = np.array(np.arange(1,6))  # [1 2 3 4 5]<br>np_array_2 = np.array(np.arange(6,11))  # [6 7 8 9 10]<br>print(&quot;Array 1 --&gt;&quot;, np_array_1, &quot;Array 2 --&gt;&quot;, np_array_2)<br>print(&quot;Addition --&gt;&quot;, np.add(np_array_1, np_array_2))  # [7 9 11 13 15]<br>print(&quot;Multiplication --&gt;&quot;, np.multiply(np_array_1, np_array_2))  # [6 14 24 36 50]<br>print(&quot;Power (Array1 ^ 2) --&gt;&quot;, np.power(np_array_1, 2))  # [1 4 9 16 25]<br>print(&quot;Sine of Array1 --&gt;&quot;, np.sin(np_array_1))  # sin values, similarly np.cos, np.tan, np.cosh, np.tanh<br>print(&quot;Exponential (e^Array1) --&gt;&quot;, np.exp(np_array_1))  # [e^1, e^2, ...]<br>print(&quot;Logarithm of Array1 --&gt;&quot;, np.log(np_array_1))  # natural log<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Cumulative sum of Array1 --&gt;&quot;, np.cumsum(np_array_1))  # [1 3 6 10 15]<br>print(&quot;Cumulative product of Array1 --&gt;&quot;, np.cumprod(np_array_1))  # [1 2 6 24 120]<br>print(&quot;Clipped Array2 between 3 and 8 --&gt;&quot;, np.clip(np_array_2, 3, 8))  # [6 7 8 8 8] All values &lt;3 become 3, &gt;8 become 8<br>print(&quot;===================================================================================&quot;)<br>a_float = np.array([1.234, 2.678, 3.789])<br>print(&quot;Original float array --&gt;&quot;, a_float)<br>print(&quot;Rounding to integer --&gt;&quot;, np.round(a_float)) # it eliminates all the digits after the decimal point by default<br>print(&quot;Rounded values (2 decimals) --&gt;&quot;, np.round(a_float, 2))  # [1.23 2.68 3.79]<br>print(&quot;Absolute values --&gt;&quot;, np.abs(np.array([-1, -2, 3])))  # [1 2 3]<br>print(&quot;===================================================================================&quot;)<br>### Element-wise Comparison<br>print(&quot;Greater --&gt;&quot;, np.greater(np_array_2, np_array_1))  # [True True True True True]<br>print(&quot;Less --&gt;&quot;, np.less(np_array_2, np_array_1))  # [False False False False False]<br>print(&quot;Greater Equal --&gt;&quot;, np.greater_equal(np_array_2, np_array_1))  # [True True True True True]<br>print(&quot;Less Equal --&gt;&quot;, np.less_equal(np_array_1, np_array_2))  # [True True True True True]<br>print(&quot;Equal --&gt;&quot;, np.equal(np_array_1, np_array_2))  # [False False False False False]<br>print(&quot;Not Equal --&gt;&quot;, np.not_equal(np_array_1, np_array_2))  # [True True True True True]<br>print(&quot;===================================================================================&quot;)<br>### Bitwise Operations<br>print(&quot;Bitwise AND of 1 &amp; 1 --&gt;&quot;, np.bitwise_and(1, 1))  # 1<br>print(&quot;Bitwise NOT of 20 --&gt;&quot;, np.bitwise_not(20))  # ~20 = -21 (0001 0100 (20) -&gt; flips all bits = -21 (2&#39;s complement form))<br>print(&quot;Left shift 20 by 1 --&gt;&quot;, np.left_shift(20, 1))  # 20 = 0001 0100 -&gt; Shift left by 1 -&gt; 0010 1000 = 40<br>print(&quot;Right shift 10 by 1 --&gt;&quot;, np.right_shift(10, 1))  # 10 = 0000 1010 -&gt; Shift right by 1 → 0000 0101 = 5<br>print(&quot;Binary representation of 100 --&gt;&quot;, np.binary_repr(100))  # &#39;1100100&#39;<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Array 1 --&gt; [1 2 3 4 5] Array 2 --&gt; [ 6  7  8  9 10]<br>Addition --&gt; [ 7  9 11 13 15]<br>Multiplication --&gt; [ 6 14 24 36 50]<br>Power (Array1 ^ 2) --&gt; [ 1  4  9 16 25]<br>Sine of Array1 --&gt; [ 0.84147098  0.90929743  0.14112001 -0.7568025  -0.95892427]<br>Exponential (e^Array1) --&gt; [  2.71828183   7.3890561   20.08553692  54.59815003 148.4131591 ]<br>Logarithm of Array1 --&gt; [0.         0.69314718 1.09861229 1.38629436 1.60943791]<br>===================================================================================<br>Cumulative sum of Array1 --&gt; [ 1  3  6 10 15]<br>Cumulative product of Array1 --&gt; [  1   2   6  24 120]<br>Clipped Array2 between 3 and 8 --&gt; [6 7 8 8 8]<br>===================================================================================<br>Original float array --&gt; [1.234 2.678 3.789]<br>Rounding to integer --&gt; [1. 3. 4.]<br>Rounded values (2 decimals) --&gt; [1.23 2.68 3.79]<br>Absolute values --&gt; [1 2 3]<br>===================================================================================<br>Greater --&gt; [ True  True  True  True  True]<br>Less --&gt; [False False False False False]<br>Greater Equal --&gt; [ True  True  True  True  True]<br>Less Equal --&gt; [ True  True  True  True  True]<br>Equal --&gt; [False False False False False]<br>Not Equal --&gt; [ True  True  True  True  True]<br>===================================================================================<br>Bitwise AND of 1 &amp; 1 --&gt; 1<br>Bitwise NOT of 20 --&gt; -21<br>Left shift 20 by 1 --&gt; 40<br>Right shift 10 by 1 --&gt; 5<br>Binary representation of 100 --&gt; 1100100<br>===================================================================================</pre><h4>Commonly Used Functions in NumPy</h4><p>Once you’ve created an array, the real magic of NumPy lies in its built-in functions that help you <strong>analyze, filter, and work with data</strong> effortlessly — without writing any loops.</p><p>In this section, we’ll explore powerful utility functions that help us perform:</p><ul><li><strong>Sorting</strong>: np.sort() gives you a sorted array, while np.argsort() tells you the positions that would sort the array.</li><li><strong>Finding Extremes</strong>: np.argmax() and np.argmin() return the indices of the max and min values in the array.</li><li><strong>Uniqueness</strong>: np.unique() extracts all unique values and can even tell you how to reconstruct the original using inverse indices.</li><li><strong>Filtering</strong>: Use boolean indexing (np_array &gt; 3) or np.where() to find values or positions matching conditions.</li><li><strong>Counts and Checks</strong>: Want to count how many values are non-zero? Or check if <em>any</em> or <em>all</em> values meet a condition? Use np.count_nonzero(), np.any(), and np.all() for that.</li><li><strong>Testing</strong>: With np.isin(), you can check which elements belong to a specific list — great for filtering by category or tags.</li></ul><p>These functions are <strong>essential for real-world data analysis</strong> where identifying patterns, filtering data, or summarizing values is a daily task. And the best part? Everything works on entire arrays at once — fast and clean!</p><pre>np_array = np.array([0,1,2,3,1,1,2,2,4,4,5,5,3,3])<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Original Array --&gt;&quot;, np_array)  # 1D array with repeated elements<br>print(&quot;Index of max value --&gt;&quot;, np.argmax(np_array)) # Index of highest value at its first occurence<br>print(&quot;Index of min value --&gt;&quot;, np.argmin(np_array)) # Index of lowest value at its first occurence<br>print(&quot;Sorted Array --&gt;&quot;, np.sort(np_array))  # Sort the array<br>print(&quot;Indices to sort the array --&gt;&quot;, np.argsort(np_array))  # Indices/Positions that would sort the array<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Unique elements --&gt;&quot;, np.unique(np_array))  # [1 2 3 4 5] Returns sorted unique elements from the array<br>unique_vals, indices = np.unique(np_array, return_inverse=True) <br>print(&quot;Unique values, Indices --&gt;&quot;, unique_vals, indices)  # Return unique values as well as indices to reconstruct<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Elements where values &gt; 3 --&gt;&quot;, np_array[np_array&gt;3]) # Filters values greater than 3<br>print(&quot;Indices where values &gt; 3 --&gt;&quot;, np.where(np_array &gt; 3)) # Gives the positions (indices) where values are greater than 3<br>print(&quot;===================================================================================&quot;)<br>print(&quot;Count of elements and non-zero elements --&gt;&quot;, len(np_array), &quot;&amp;&quot;,  np.count_nonzero(np_array))  # Total and non-zero counts<br>print(&quot;Any element &gt; 3? --&gt;&quot;, np.any(np_array &gt; 3))  # True if any value &gt; 3<br>print(&quot;All elements &gt; 0? --&gt;&quot;, np.all(np_array &gt; -1))  # True if all values &gt; -1<br>print(&quot;===================================================================================&quot;)<br>check_vals = [2, 4]<br>print(&quot;Is element in [2, 4]? --&gt;&quot;, np.isin(np_array, check_vals))  # Checks each element if it exists in [2, 4]<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Original Array --&gt; [0 1 2 3 1 1 2 2 4 4 5 5 3 3]<br>Index of max value --&gt; 10<br>Index of min value --&gt; 0<br>Sorted Array --&gt; [0 1 1 1 2 2 2 3 3 3 4 4 5 5]<br>Indices to sort the array --&gt; [ 0  1  4  5  2  6  7  3 12 13  8  9 10 11]<br>===================================================================================<br>Unique elements --&gt; [0 1 2 3 4 5]<br>Unique values, Indices --&gt; [0 1 2 3 4 5] [0 1 2 3 1 1 2 2 4 4 5 5 3 3]<br>===================================================================================<br>Elements where values &gt; 3 --&gt; [4 4 5 5]<br>Indices where values &gt; 3 --&gt; (array([ 8,  9, 10, 11], dtype=int64),)<br>===================================================================================<br>Count of elements and non-zero elements --&gt; 14 &amp; 13<br>Any element &gt; 3? --&gt; True<br>All elements &gt; 0? --&gt; True<br>===================================================================================<br>Is element in [2, 4]? --&gt; [False False  True False False False  True  True  True  True False False<br> False False]<br>===================================================================================</pre><h4>Working with Strings in NumPy</h4><p>While NumPy is famous for handling numbers efficiently, it also includes a powerful np.char module for <strong>string operations</strong> on arrays of text.</p><p>This section shows how you can use NumPy to perform:</p><ul><li><strong>Case conversions</strong> like converting to lowercase, uppercase, capitalizing, or title-casing a string.</li><li><strong>Splitting</strong> strings based on a delimiter and <strong>joining</strong> characters with custom separators.</li><li><strong>Whitespace removal</strong> from both ends or one side of a string.</li><li><strong>Encoding</strong> strings into byte format using UTF-8.</li><li><strong>Replacing</strong> substrings and <strong>counting</strong> character occurrences.</li><li><strong>Checking</strong> if a string is alphabetic or numeric.</li><li><strong>Validating start and end</strong> of strings using startswith() and endswith().</li></ul><p>These string functions are especially useful when you’re dealing with <strong>arrays of strings</strong>, enabling you to apply operations across the whole array without using loops. Even though strings are not NumPy’s main use case, these utilities make text handling more convenient when you’re working with structured or tabular data.</p><pre>print(&quot;===================================================================================&quot;)<br># Case conversions<br>print(&quot;Lowercase --&gt;&quot;, np.char.lower(&quot;HELLOWORLD&quot;))       # → helloworld<br>print(&quot;Uppercase --&gt;&quot;, np.char.upper(&quot;helloworld&quot;))       # → HELLOWORLD<br>print(&quot;Capitalize --&gt;&quot;, np.char.capitalize(&quot;helloWORLD&quot;)) # → Helloworld<br>print(&quot;Title Case --&gt;&quot;, np.char.title(&quot;hello world test&quot;))# → Hello World Test<br>print(&quot;===================================================================================&quot;)<br># Splitting and joining<br>print(&quot;Split by comma --&gt;&quot;, np.char.split(&quot;HELL,O,WORLD&quot;, sep=&quot;,&quot;))  # → [&#39;H&#39;, &#39;E&#39;, ..., &#39;D&#39;]<br>print(&quot;Join with hyphen --&gt;&quot;, np.char.join(&quot;-&quot;, &quot;HelloWorld&quot;))  # → H-e-l-l-o-W-o-r-l-d<br>print(&quot;Join with custom separators --&gt;&quot;, np.char.join([&quot;-&quot;, &quot;---&quot;], [&quot;Hello&quot;, &quot;World&quot;]))  # → H-e-l-l-o  W---o---r---l---d<br>print(&quot;===================================================================================&quot;)<br># Stripping whitespace<br>print(&quot;Strip both sides --&gt;&quot;, np.char.strip(&quot;   HelloWorld   &quot;))   # → &#39;HelloWorld&#39;<br>print(&quot;Left strip --&gt;&quot;, np.char.lstrip(&quot;   HelloWorld   &quot;))        # → &#39;HelloWorld   &#39;<br>print(&quot;Right strip --&gt;&quot;, np.char.rstrip(&quot;   HelloWorld   &quot;))       # → &#39;   HelloWorld&#39;<br>print(&quot;===================================================================================&quot;)<br># Encoding (to bytes)<br>print(&quot;UTF-8 Encoded --&gt;&quot;, np.char.encode(&quot;HelloWorld&quot;, encoding=&#39;utf-8&#39;))  # → b&#39;HelloWorld&#39;<br>print(&quot;===================================================================================&quot;)<br># Replace, Count, Check types<br>print(&quot;Replace &#39;World&#39; with &#39;NumPy&#39; --&gt;&quot;, np.char.replace(&quot;HelloWorld&quot;, &quot;World&quot;, &quot;NumPy&quot;))  # → HelloNumPy<br>print(&quot;Count of &#39;l&#39; --&gt;&quot;, np.char.count(&quot;HelloWorld&quot;, &quot;l&quot;))  # → 3<br>print(&quot;Is alphabetic? --&gt;&quot;, np.char.isalpha(&quot;HelloWorld&quot;))   # → True<br>print(&quot;Is numeric? --&gt;&quot;, np.char.isnumeric(&quot;12345&quot;))         # → True<br>print(&quot;===================================================================================&quot;)<br># Startswith / Endswith<br>print(&quot;Starts with &#39;Hello&#39;? --&gt;&quot;, np.char.startswith(&quot;HelloWorld&quot;, &quot;Hello&quot;))  # → True<br>print(&quot;Ends with &#39;World&#39;? --&gt;&quot;, np.char.endswith(&quot;HelloWorld&quot;, &quot;World&quot;))      # → True<br>print(&quot;===================================================================================&quot;)</pre><pre>===================================================================================<br>Lowercase --&gt; helloworld<br>Uppercase --&gt; HELLOWORLD<br>Capitalize --&gt; Helloworld<br>Title Case --&gt; Hello World Test<br>===================================================================================<br>Split by comma --&gt; [&#39;HELL&#39;, &#39;O&#39;, &#39;WORLD&#39;]<br>Join with hyphen --&gt; H-e-l-l-o-W-o-r-l-d<br>Join with custom separators --&gt; [&#39;H-e-l-l-o&#39; &#39;W---o---r---l---d&#39;]<br>===================================================================================<br>Strip both sides --&gt; HelloWorld<br>Left strip --&gt; HelloWorld   <br>Right strip --&gt;    HelloWorld<br>===================================================================================<br>UTF-8 Encoded --&gt; b&#39;HelloWorld&#39;<br>===================================================================================<br>Replace &#39;World&#39; with &#39;NumPy&#39; --&gt; HelloNumPy<br>Count of &#39;l&#39; --&gt; 3<br>Is alphabetic? --&gt; True<br>Is numeric? --&gt; True<br>===================================================================================<br>Starts with &#39;Hello&#39;? --&gt; True<br>Ends with &#39;World&#39;? --&gt; True<br>===================================================================================</pre><h3>Thanks for Reaching the End!</h3><p><strong>If you’ve made it this far — give yourself a high five! 🙌</strong></p><p>We started with the <strong>basics of NumPy and slowly worked our way through arrays, operations, random numbers, statistics, and even string handling</strong>.</p><p>By now, you’ve seen how powerful and beginner-friendly NumPy really is. Whether you’re stepping into data science, machine learning, or <strong>just want to handle data better</strong> — this is a skill worth having.</p><p>Keep exploring, experiment with the code, break things, fix them — and most importantly, stay curious.</p><p>This blog was written to give you a friendly, step-by-step introduction. If you followed the examples, played with the code, and understood how things work — you’ve already taken your first solid step toward data science.</p><p>Now that you’re comfortable with NumPy, a great next step is to explore libraries like <strong>Pandas, Matplotlib, and Scikit-learn</strong> — all of which are built on NumPy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=005507d89cb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>