Skip to content

Tag: pandas

Compare two pandas series and remove duplicates

I have two series: I want to compare ser1 and ser2 and then remove the duplicates and put the result into ser1 to have something like this: I tried pd.concat but this gave me the combination of the two series without removing the duplicates. Answer

Compare two dataframe columns on a histogram

I have a dataframe that looks similar to: I am required to give a visual comparison of true and estimated distances. My actual df shape is: How do I show true_distance side-by-side estimated_distance on a plot, where one can easily see the difference in each row, considering the side of my df_actual? Answer H…

Determinate Consecutive Values (Invoices) Pandas

I have a dataset with supplier and its invoices and I need to determinate which of the invoices are consecutives marking it with a 1 or a 0. For example: And what I want is a third column like this: EDIT Thanks for your answers, this options works great, but when I tried it in a real database I realized

Select rows from a pandas dataframe using a set of values

I have a dataframe with a column named label_id which is a string value. I also have a set of label_id values in required_labels. I would like to select the rows of the dataframe where the label_id value is contained in the set. I understand that I need to use df.loc for this, but when I try to generate a

Append new level to DataFrame column

Given a DataFrame, how can I add a new level to the columns based on an iterable given by the user? In other words, how do I append a new level? The question How to simply add a column level to a pandas dataframe shows how to add a new level given a single value, so it doesn’t cover this