Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 331 of 2109
Python - How to reset index after Groupby pandas?
When you perform a groupby operation in pandas, the grouped column becomes the index. To convert this index back to a regular column, use reset_index(). Import Required Library First, import pandas ? import pandas as pd Creating Sample DataFrame Let's create a DataFrame with car names and prices ? import pandas as pd dataFrame = pd.DataFrame({ "Car": ["Audi", "Lexus", "Audi", "Mercedes", "Audi", "Lexus", "Mercedes", "Lexus", "Mercedes"], "Reg_Price": [1000, 1400, 1100, 900, 1700, 1800, 1300, 1150, 1350] }) print("Original DataFrame:") print(dataFrame) ...
Read MorePython - Sum only specific rows of a Pandas Dataframe
To sum only specific rows in a Pandas DataFrame, use the loc[] method to select specific row ranges and columns. The loc[] method allows you to specify both row indices and column names for precise data selection. Let's start by creating a DataFrame with product inventory data ? import pandas as pd # Create DataFrame with product inventory data dataFrame = pd.DataFrame({ "Product": ["SmartTV", "ChromeCast", "Speaker", "Earphone"], "Opening_Stock": [300, 700, 1200, 1500], "Closing_Stock": [200, 500, 1000, 900] }) print("Original DataFrame:") print(dataFrame) ...
Read MorePython Pandas – Find the common rows between two Data Frames
To find the common rows between two DataFrames in Pandas, use the merge() method with how='inner'. This returns only the rows that have identical values across all columns in both DataFrames. Creating Sample DataFrames Let us first create two DataFrames with car data ? import pandas as pd # Create DataFrame1 dataFrame1 = pd.DataFrame({ "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] }) print("DataFrame1:") print(dataFrame1) DataFrame1: Car Units 0 ...
Read MorePython Pandas – Check if any specific column of two DataFrames are equal or not
To check if any specific column of two DataFrames are equal or not, use the equals() method. This method compares both the values and the structure of the columns, returning True if they are identical. Creating Sample DataFrames Let us first create DataFrame1 with two columns − import pandas as pd dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } ) ...
Read MorePython - Calculate the mean of column values of a Pandas DataFrame
To calculate the mean of column values in a Pandas DataFrame, use the mean() method. This method computes the arithmetic average of numeric columns, making it essential for data analysis tasks. Basic Syntax The basic syntax for calculating column mean is ? # For a single column dataframe['column_name'].mean() # For all numeric columns dataframe.mean() Creating Sample DataFrames Let's create two DataFrames to demonstrate mean calculations ? import pandas as pd # Create DataFrame1 with car data dataFrame1 = pd.DataFrame({ "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', ...
Read MorePython - Create a Pipeline in Pandas
To create a pipeline in Pandas, we use the pipe() 100] def add_category(df): df['CATEGORY'] = 'Premium' return df # Create DataFrame df = pd.DataFrame({ "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] }) # Chain multiple operations result = (df.pipe(uppercase_columns) .pipe(filter_high_units) .pipe(add_category)) print("Final result after pipeline:") print(result) ...
Read MorePython Pandas and Numpy - Concatenate multiindex into single index
To concatenate a multiindex into a single index in Pandas, we can use the map() method with join() to combine tuple elements with a separator. Let us start by importing the required libraries ? Import Libraries import pandas as pd import numpy as np Creating a Series with Tuple Index First, we create a Pandas Series with tuples as index values ? # Create tuples for multiindex index_tuples = [('Jacob', 'North'), ('Ami', 'East'), ('Ami', 'West'), ...
Read MorePython - Typecasting Pandas into set
To typecast Pandas DataFrame columns into a set, use the set() function. This is useful for removing duplicates and performing set operations like union, intersection, and difference. Creating a DataFrame Let us first create a DataFrame with employee data ? import pandas as pd # Create DataFrame dataFrame = pd.DataFrame( { "EmpName": ['John', 'Ted', 'Jacob', 'Scarlett', 'Ami', 'Ted', 'Scarlett'], "Zone": ['North', 'South', 'South', 'East', 'West', 'East', 'North'] } ) print("DataFrame:") print(dataFrame) DataFrame: ...
Read MoreWhat is digital certificate and digital signature?
Digital certificates and digital signatures are fundamental concepts in cybersecurity that ensure secure communication and data integrity. Let's explore both concepts and understand how they work together to provide authentication and security. Digital Certificate A digital certificate is an electronic document issued by a trusted Certificate Authority (CA) that verifies the identity of an individual, organization, or device. It contains the entity's public key and identifying information, digitally signed by the CA to guarantee authenticity. Components of a Digital Certificate A digital certificate typically contains ? Subject's public key − Used for encryption and ...
Read MorePython Pandas - Finding the uncommon rows between two DataFrames
To find the uncommon rows between two DataFrames, you can use concat() combined with drop_duplicates(). This approach concatenates both DataFrames and removes duplicate rows, leaving only the uncommon ones. Syntax pd.concat([df1, df2]).drop_duplicates(keep=False) Where keep=False removes all occurrences of duplicated rows, leaving only the unique rows from each DataFrame. Example Let's create two DataFrames with car data and find the uncommon rows ? import pandas as pd # Create DataFrame1 dataFrame1 = pd.DataFrame({ "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Reg_Price": [1000, 1500, ...
Read More