Skip to content

Tag: pandas

pandas subtracting value in another column from previous row

I have a dataframe (named df) sorted by identifier, id_number and contract_year_month in order like this so far: and would like to add a column named ‘date_difference’ that is consisted of contract_year_month minus collection_year_month from previous row based on identifier and id_number (e.g. 201…

Cannot convert the series to [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about programming within the scope defined in the help center. Closed last year. The community reviewed whether to reopen this question 8 months ago and left it closed: Ori…

Alternative to the pandas negation operator

I’m trying to use the pandas negation operator ~ in one of my jinja2 templates but I believe its conflicting with their special operator ~. yields the following exception… I could do the operation on the python side and pass another variable with the negated selection but what’s the method n…

return last date and value each month in pandas

I have a df in pandas with daily data. I would like to return the last value of each month. I thought the simple solution would be to .resample(“M”).apply(lambda ser: ser.iloc[-1,]) however, it seems as if resample actually computes the month end date rather than return the actual date that appear…