Skip to content
Advertisement

Tag: fillna

How do i df.fillna with category median values

I have a large dataset ~1mln rows, and about 5000 absent coordinates(i’d like to fill them with median value by category ‘city’everything but fillna is working, how to make it happen? Answer You could do: First groupby with the city, then use transform with fillna and calculate the median. (you could use any mathematical operation)

Faster alternative to groupby, unstack then fillna

I’m currently doing the following operations based on a dataframe (A) made of two columns with multiple thousands of unique values each. The operations performed on this dataframe are: The output is a table (B) with unique values of col1 in rows and unique values of col2 in columns, and each cell is the count of rows, from the original

Advertisement