Reputation: 9763
I got my data sorted correctly, but now Im trying to find a way to group by "first not empty string value". Is there a way to do this without changing the rest of the data? First was close, but not quite what I needed
grouped = sortedvals.groupby(['name']).first().reset_index()
doesnt work if the first value is empty ie: '',2
(my goal is to return 2) but does work for everything else.
Upvotes: 0
Views: 53
Reputation: 323276
Use
replace
function to replace blank values withnp.nan
import numpy as np
grouped = sortedvals.replace('',np.nan).groupby(['name']).first().reset_index()
Upvotes: 1