inner join with group by pandas python -
i have 2 dataframes named geostat , ref, dataframes follows:
geostat: count percent grpno. state code 0 14.78 1 ca 1 0.00 2 ca 2 8.80 3 ca 3 9.60 4 fl 4 55.90 4 ma 5 0.00 2 fl 6 0.00 6 nc 7 0.00 5 nc 8 6.90 1 fl 9 59.00 4 ma res: grpno. maxofcount percent 0 1 14.78 1 2 0.00 2 3 8.80 3 4 59.00 4 5 0.00 5 6 0.00
i want select first(res.maxofcount percent), res.grpno., , geostat.first(statecode) dataframe geostat , res inner join on columns res.maxofcount percent = geostat.count percent , res. grpno. = geostat.grpno. group res.grpno.
i want python pandas, not sure on how inner join group by.can me on this?
the output dataframe given below:
firstofmaxofstate count percent state pool number firstofstate code 0 14.78 1 ca 1 0.00 2 ca 2 8.80 3 ca 3 59.00 4 ma 4 0.00 5 nc 5 0.00 6 nc
note: first(column name) access function should equivalent of in python?
edited: changed output dataframe.
geostat.merge(res, left_on=['count percent', 'grpno.'], right_on=['maxofcount percent', 'grpno.'],how='inner') count percent grpno. state code maxofcount percent 0 14.78 1 ca 14.78 1 0.00 2 ca 0.00 2 0.00 2 fl 0.00 3 8.80 3 ca 8.80 4 0.00 6 nc 0.00 5 0.00 5 nc 0.00 6 59.00 4 ma 59.00
Comments
Post a Comment