Skip to content
Advertisement

Tag: dataframe

How to replace NaN value in column in Dataframe based on values from another column in same dataframe

Below is the Dataframe i’m working. I want to replace NaN values in ‘Score’ columns using values from column ‘Country’ and ‘Sectors’ Below is the code which I’ve tried I want to replace only NaN values specific to country == ‘USA’ and Sectors == ‘CHEM’ and keep all values as it is. Could anyone please help?“` Answer You can use

Python: How to One Hot Encode a Feature with multiple values?

I have the following dataframe df with names of the travelling cities in route column of an aircraft with it’s ticket_price. I want to obtain individual city names from route and one hot encode them. Dataframe (df) Required Dataframe (df_encoded) Code I have performed some preprocessing on the route column using the following code but am unable to understand how

How to drop rows in one DataFrame based on one similar column in another Dataframe that has a different number of rows

I have two DataFrames that are completely dissimilar except for certain values in one particular column: How would I go about finding the matching values in the Email column of df and the Contact column of df2, and then dropping the whole row in df based on that match? Output I’m looking for (index numbering doesn’t matter): I’ve been able

Python Regex DataFrame match

I have a DataFrame and I would like to perform a sorting if the match between my regex and the name of one of the lines of this DataFrame matches. Is there an option in the “re” library to help me? I try with this piece of code but without success Thank you in advance for your answers Answer I

Pandas merge indexing not behaving as expected

I am trying to perform an anti-join in effectively one line. However, my one line solution is not giving me the same results that a receive when breaking up the code into two lines (which behaves as expected). Specifically, the single-line solution results in a dataframe with fewer rows. The goal of my anti-join is to remove any overlap of

Pandas deleting rows based on same sting in columns

Hello i am using pandas DataFrame to clean this file and want to delete rows which contains the manufacturers name in the buy-box seller column. For example row 1 will be deleted because it contains the string ‘Goli’ in Buy-Box seller Column. Answer There are misisng values so first replace them by DataFrame.fillna and then test if match values between

Manipulate string to drop columns on pandas

I’m trying to manipulate a list (type: string) to use that list to drop some columns from a dataframe. Dataframe The list is from a dataframe that I created a condition to return columns whose sums of all values ​​are zero: Selecting the columns with sum = 0 Importing the dataframe and turning it into a list: Images from the

Advertisement