Skip to content

Tag: dataframe

df.explode() function not working in python

I am facing a weird issue, I have a column name ‘window’ in a data frame and it has a list of values i.e., [3,9,45,78]. I am trying to explode this column using df.explode(‘window’) but this is doing no job. datatype of ‘window’ column is object. I have checked my pandas ve…

Python Trim Multiple Column Names of a dataframe

I have data frame of 20 columns. All of them have a common text and a serial number. I want to trim the text part and make the name shorter. Below is an example: Expected output: Solution1: Solution2: Solution1 works fine but I have to prepare an old and new column names list. Instead, I want to iterate throu…

Pandas groupby counting values > 0

I have a pandas df of the following format I am looking to transform it such that I land up with the below result Essentially for “HIGH_COUNT” and “LOW_COUNT” I want to count the number of occurrences that column was greater than 0, grouped by “MATERIAL”. I have tried to do…

Pandas apply/lambda on multiple columns

I have a simple script transforming data in a dataframe: The above seems to work fine. I have tried rewriting the last two lines to: However, this fails and gives a value error: I am trying to understand why it can’t be used in the above way. My pad_value function seems clunky – I wonder if there …