Close Menu
    Trending
    • How Smart Entrepreneurs Turn Mid-Year Tax Reviews Into Long-Term Financial Wins
    • Become a Better Data Scientist with These Prompt Engineering Tips and Tricks
    • Meanwhile in Europe: How We Learned to Stop Worrying and Love the AI Angst | by Andreas Maier | Jul, 2025
    • Transform Complexity into Opportunity with Digital Engineering
    • OpenAI Is Fighting Back Against Meta Poaching AI Talent
    • Lessons Learned After 6.5 Years Of Machine Learning
    • Handling Big Git Repos in AI Development | by Rajarshi Karmakar | Jul, 2025
    • National Lab’s Machine Learning Project to Advance Seismic Monitoring Across Energy Industries
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»A Beginner’s Guide to Numpy and Pandas | by Yuvraj Singh | Dec, 2024
    Machine Learning

    A Beginner’s Guide to Numpy and Pandas | by Yuvraj Singh | Dec, 2024

    Team_AIBS NewsBy Team_AIBS NewsDecember 18, 2024No Comments3 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    A Newbie’s Information to Numpy and Pandas

    Numpy stands for numerical python. It’s used for numerical computations and enabling you to work with array and matrices.

    Creating arrays

    Numpy arrays are the central knowledge construction within the library. Listed below are some methods to create them:

    import numpy as np

    # creating 1-d array
    arr1 = np.array([1,2,3,4,5])
    # making a second array
    arr2 = np.array([[1,2,3],[4,5,6]])
    # making a array zeroes
    zeros = np.zeros((2, 3))
    # Creating an array of ones
    ones = np.ones((2, 3))
    # Creating an array with a variety of values
    range_array = np.arange(0, 10, 2)
    # Creating an array of random values
    random_array = np.random.rand(2, 3)

    Array Operations

    # Aspect-wise addition
    arr_sum = arr1 + arr1

    # Aspect-wise multiplication
    arr_product = arr1 * arr1

    # Dot product
    arr_dot = np.dot(arr1, arr1)

    # Broadcasting (including a scalar to an array)
    broadcast_arr = arr1 + 5

    Indexing and slicing

    You may entry components and sub-arrays utilizing indexing and slicing.

    # Accessing a single component
    component = arr1[0]

    # Slicing a 2D array
    sub_array = arr2[:, 1:3]

    Statistical Operations

    Numpy offers varied features for statistical evaluation.

    # Calculate imply
    imply = np.imply(arr1)

    # Calculate median
    median = np.median(arr1)

    # Calculate customary deviation
    std1 = np.std(arr1)

    Reshaping and Transposing

    You may change the form of arrays and transpose them.

    # Reshape an array
    reshaped_arr = arr2.reshape((3, 2))

    # Transpose an array
    transposed_arr = arr2.T

    A strong library for knowledge manipulation and evaluation in Python.

    Information Constructions

    Pandas has two major knowledge buildings:

    • Sequence: A one-dimensional array-like object.
    • DataFrame: A two-dimensional desk with rows and columns.

    Creating Information Constructions

    You may create Sequence and DataFrames as follows.

    import pandas as pd

    # Create a Sequence
    s = pd.Sequence([1, 3, 5, np.nan, 6, 8])

    # Create a DataFrame
    df = pd.DataFrame({
    'A': [1, 2, 3, 4],
    'B': [5, 6, 7, 8],
    'C': ['x', 'y', 'z', 'w']
    })

    Studying Information

    Learn knowledge from varied file codecs.

    # Learn CSV file
    df = pd.read_csv('file.csv')

    # Learn Excel file
    df = pd.read_excel('file.xlsx')

    # Learn SQL question
    import sqlite3
    conn = sqlite3.join('database.db')
    df = pd.read_sql_query("SELECT * FROM table_name", conn)

    Information Inspection

    Examine your knowledge to know its construction.

    # Show the primary few rows
    print(df.head())

    # Show the previous few rows
    print(df.tail())

    # Get fundamental details about the DataFrame
    print(df.data())

    # Abstract statistics
    print(df.describe())

    Information Choice

    Choose particular rows and columns.

    # Choose a single column
    print(df['A'])

    # Choose a number of columns
    print(df[['A', 'B']])

    # Choose rows by index
    print(df.iloc[0:3])

    # Choose rows and columns by label
    print(df.loc[0:3, ['A', 'B']])

    Information Cleansing

    Clear and put together your knowledge.

    # Drop lacking values
    df = df.dropna()

    # Fill lacking values
    df = df.fillna(worth=0)

    # Exchange values
    df = df.change(to_replace='x', worth='z')

    Information Transformation

    Remodel your knowledge for evaluation.

    # Rename columns
    df = df.rename(columns={'A': 'new_A'})

    # Apply a perform to every column
    df['A'] = df['A'].apply(lambda x: x*2)

    # Apply a perform to every row
    df['sum'] = df.apply(lambda row: row.A + row.B, axis=1)

    Information Aggregation and Grouping

    Group knowledge and carry out aggregation operations.

    # Group by a column and calculate imply
    grouped = df.groupby('C').imply()

    # Pivot tables
    pivot_table = df.pivot_table(values='A', index='C', columns='B')

    Superior Options

    Discover extra superior functionalities.

    # Merge two DataFrames
    merged_df = pd.merge(df1, df2, on='key')

    # Be part of DataFrames
    joined_df = df1.be part of(df2, on='key')

    # Parse dates
    df['date'] = pd.to_datetime(df['date'])

    # Set date as index
    df.set_index('date', inplace=True)

    # Resample knowledge
    df.resample('M').imply()



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleFishing for Leads: How to Reel in Success with Insurance CRM Software
    Next Article This is where the data to build AI comes from
    Team_AIBS News
    • Website

    Related Posts

    Machine Learning

    Meanwhile in Europe: How We Learned to Stop Worrying and Love the AI Angst | by Andreas Maier | Jul, 2025

    July 1, 2025
    Machine Learning

    Handling Big Git Repos in AI Development | by Rajarshi Karmakar | Jul, 2025

    July 1, 2025
    Machine Learning

    A Technical Overview of the Attention Mechanism in Deep Learning | by Silva.f.francis | Jun, 2025

    June 30, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    How Smart Entrepreneurs Turn Mid-Year Tax Reviews Into Long-Term Financial Wins

    July 1, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    Understanding Data Preprocessing: A Critical Step in Data Science | by evrencagilci | Dec, 2024

    December 22, 2024

    How InMyExpertOpinion Is Battling AI Product Reviews

    June 24, 2025

    The Future of AI in Enhancing Virtual Intimacy

    March 19, 2025
    Our Picks

    How Smart Entrepreneurs Turn Mid-Year Tax Reviews Into Long-Term Financial Wins

    July 1, 2025

    Become a Better Data Scientist with These Prompt Engineering Tips and Tricks

    July 1, 2025

    Meanwhile in Europe: How We Learned to Stop Worrying and Love the AI Angst | by Andreas Maier | Jul, 2025

    July 1, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.