Skip to content

Tag: pandas

Merging pandas get_dummies back to categorical values

I have a pandas dataframe which I have one hot encoded with get_dummies, the data previously had a ‘type’ column which contained the values small_airport, large_airport, medium_airport, I split the type column in to each different type of airport with 1s and 0s where the frequencies matched. After…

Add missing rows in pandas DataFrame

I have a DataFrame that looks like this: What I want to get is: In short, for each id, add the time rows missing with value 0. How do I do this? I wrote something with a loop, but it’s going to be prohibitively slow for my use case which has several million rows Answer Here’s one way using groupby…