Found 10476 Articles for Python

Python Pandas – Check if any specific column of two DataFrames are equal or not

AmitDiwan
Updated on 15-Sep-2021 08:49:18

372 Views

To check if any specific column of two DataFrames are equal or not, use the equals() method. Let us first create DataFrame1 with two columns −dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Create DataFrame2 with two columns −dataFrame2 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Mercedes', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] ... Read More

Python - Calculate the mean of column values of a Pandas DataFrame

AmitDiwan
Updated on 15-Sep-2021 08:42:35

751 Views

To calculate the mean of column values, use the mean() method. At first, import the required Pandas library −import pandas as pdNow, create a DataFrame with two columns −dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Finding the mean of a single column “Units” using mean() −print"Mean of Units column from DataFrame1 = ", dataFrame1['Units'].mean()In the same way, we have calculated the mean value from the 2nd DataFrame.ExampleFollowing is the complete code −import pandas ... Read More

Python - Create a Pipeline in Pandas

AmitDiwan
Updated on 15-Sep-2021 08:16:08

296 Views

To create a pipeline in Pandas, we need to use the pipe() method. At first, import the required pandas library with an alias −import pandas as pdNow, create a DataFrame −dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } ) Create a pipeline and call the upperFunc() custom function to convert column names to uppercase −pipeline = dataFrame.pipe(upperFunc)Following is the upperFun() to convert column names to uppercase −def upperFunc(dataframe): # Converting ... Read More

Python Pandas and Numpy - Concatenate multiindex into single index

AmitDiwan
Updated on 15-Sep-2021 08:06:10

548 Views

To concatenate multiindex into single index, at first, let us import the required Pandas and Numpy libraries with their respective aliases −import pandas as pd import numpy as np Create Pandas series −d = pd.Series([('Jacob', 'North'), ('Ami', 'East'), ('Ami', 'West'), ('Scarlett', 'South'), ('Jacob', 'West'), ('Scarlett', 'North')])Now, use the Numpy arrange() method −dataFrame = pd.Series(np.arange(1, 7), index=d) Let us now map and join −dataMap = dataFrame.index.map('_'.join)ExampleFollowing is the code −import pandas as pd import numpy as np # pandas series d = pd.Series([('Jacob', 'North'), ('Ami', 'East'), ('Ami', 'West'), ('Scarlett', 'South'), ('Jacob', 'West'), ('Scarlett', 'North')]) dataFrame = pd.Series(np.arange(1, 7), ... Read More

Python - Typecasting Pandas into set

AmitDiwan
Updated on 15-Sep-2021 07:58:46

175 Views

To typecast pandas into Set, use the set(). At first, let us create a DataFrame −dataFrame = pd.DataFrame( { "EmpName": ['John', 'Ted', 'Jacob', 'Scarlett', 'Ami', 'Ted', 'Scarlett'], "Zone": ['North', 'South', 'South', 'East', 'West', 'East', 'North'] } ) Typecast pandas to set and then take set union −set(dataFrame.EmpName) | set(dataFrame.Zone)ExampleFollowing is the complete code − import pandas as pd # Create DataFrame dataFrame = pd.DataFrame( { "EmpName": ['John', 'Ted', 'Jacob', 'Scarlett', 'Ami', ... Read More

Python Pandas – Find unique values from multiple columns

AmitDiwan
Updated on 29-Sep-2021 11:07:39

6K+ Views

To find unique values from multiple columns, use the unique() method. Let’s say you have Employee Records with “EmpName” and “Zone” in your Pandas DataFrame. The name and zone can get repeated since two employees can have similar names and a zone can have more than one employee. In that case, if you want unique Employee names, then use the unique() for DataFrame.At first, import the required library. Here, we have set pd as an alias −import pandas as pdAt first, create a DataFrame. Here, we have two columns −dataFrame = pd.DataFrame(    {       "EmpName": ['John', 'Ted', ... Read More

What is digital certificate and digital signature?

Bhanu Priya
Updated on 15-Sep-2021 07:49:04

4K+ Views

Let us begin by learning about the digital certificate.Digital CertificateIt is basically a certificate issued digitally, issued to verify a user's authenticity i.e., verifying the user sending a message is who he or she claims to be, and also to provide the receiver with the means to encode a reply.Whoever wants to or an individual who wants to send encrypted messages applies for a digital certificate from a Certificate Authority (CA).Need of digital certificateThe digital certificate allows entities to share their public key in an authenticated way. They are used in initializing and establishing secure SSL (Secure Sockets Layer) connections ... Read More

What are symmetric and Asymmetric key encryptions?

Bhanu Priya
Updated on 15-Sep-2021 07:47:02

2K+ Views

Let us understand the symmetric key encryption.Symmetric Key encryptionSymmetric-key encryption algorithms in cryptography use a single key or the same cryptographic keys (secret key) shared between the two parties for both encrypting plain-text and decrypting cipher-text. The keys could be identical or there could be a simple change to go between the two keys.It uses Diffie–Hellman key exchange or other public-key protocol to securely agree upon the sharing and usage of a fresh new secret key for each message.Asymmetric Key encryptionAsymmetric key encryption is an encryption technique using a pair of public and private keys to encrypt and decrypt plain-text ... Read More

Python Pandas - Finding the uncommon rows between two DataFrames

AmitDiwan
Updated on 15-Sep-2021 07:48:17

3K+ Views

To find the uncommon rows between two DataFrames, use the concat() method. Let us first import the required library with alias −import pandas as pdCreate DataFrame1 with two columns −dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Reg_Price": [1000, 1500, 1100, 800, 1100, 900] } )Create DataFrame2 with two columns −dataFrame2 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Reg_Price": [1000, 1300, ... Read More

How to shift a column in a Pandas DataFrame?

Rishikesh Kumar Rishi
Updated on 15-Sep-2021 07:23:13

8K+ Views

We can use the shift() method in Pandas to shift the columns of a DataFrame without having to rewrite the whole DataFrame. shift() takes the following parametersshift(self, periods=1, freq=None, axis=0, fill_value=None)periods  Number of periods to shift. It can take a negative number too.axis  It takes a Boolean value; 0 if you want to shift index and 1 if you want to shift columnfill_value  It will replace the missing value.Let's take an example and see how to use this shift() method.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Select a column and shift it by using df["column_name]=df.column_name.shift()Print ... Read More

Advertisements