Skip to content
Advertisement

Tag: pandas

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 df.groupby([‘MATERIAL’]).agg<xxx> but I am unsure of the agg function

Pandas: Find difference in rows with same index in any column

Sample dataframe: If you see here, the rows with common index have atleast one difference amongst them. For ex: Rows with index 0, have difference in column_name. Rows with index 5, have difference in max_length. Rows with index 6, have differences in both data_type and default. Rows with index 8, have difference in data_type. Expected Output: This is part of

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 is a neater

Is there any Python code to help me replace the years of every date by 2022

I have a pandas dataframe column named disbursal_date which is a datetime: and so on… I want to keep the date and month part and replace the years by 2022 for all values. I tried using df[‘disbursal_date’].map(lambda x: x.replace(year=2022)) but this didn’t work for me. Answer You need to use apply not map to run a python function on a

Advertisement