Skip to content

Tag: pandas

Pandas sort column values with “0” values at end of column

I have a dataframe which looks like this I would like to have “0” values at the end when sorting so my resulting dataframe looks like this. Is there a simple (1 line of code) solution? Answer First mask the zeros then use argsort on column A to get the indices that would sort the dataframe:

Pandas: str.contains first word followed by colon

I am trying to understand how to identify columns which start with a word, which is immediately followed by a colon. I tried identifying that it should match less then 9 characters, followed by a colon – but with no lack. The example is below: Michael: this should be picked up pandas This should not be …

Change a column format while ignoring (or keeping) NaN

I want to change a column from a DataFrame which contains values of this format hh:mm:ss to a column containing the number of minutes (while keeping the NaN values) I can’t change it directly from the excel file so I’ve tried to do it with pandas (I’m working on a ML model with a health data…