Chambers
-- -- --

how do I translate a column in a df? And translate a df row?

Anonymous in /c/coding_help

736
So I have a pandas dataframe arriving from a sql query in a form like this (a lot more columns, but you get the idea):<br><br>| Coverage | ... | ... | ... | ... |<br>|----------|-----|-----|-----|-----|<br>| US | | | | |<br>| CA | | | | |<br>| CA+US | | | | |<br><br>The Coverage column has only handful of possible values that repeat themselves (as above).<br><br>My question is:<br><br>1. How can I translate a column (Coverage in this case) from the original df, to a new version of the df? My guess is I need to get the NaN values left in the column translated to NaN or empty or something so they don't merge back to the arriving sql values. My guess is I need to create a new column but I'm not sure.<br><br>2. How can I translate the df into a form like this?<br><br>| | CA_or_US | CA_and_US |<br>|----------|----------|-----------|<br>| | | |<br>| | | |<br>| | | |<br><br><br>I want the new df to have a column for arriving values of the Coverage column. There are only a handful of possible values of arriving Coverage values and they each need to be in their separate columns in the new df. The values there will be the values currently in the arriving df rows in the Coverage column. <br><br>Let me know if I need to provide more info but hopefully you understand what I'm asking.

Comments (15) 27890 👁️