pandas.factorize on an entire data frame : <p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.factorize.html" rel="noreferrer"><code>pandas.factorize</code></a> encodes input values as an enumerated type or categorical variable. </p>

<p>But how can I easily and efficiently convert many columns of a data frame? What about the reverse mapping step?</p>

<p>Example: This data frame contains columns with string values such as "type 2" which I would like to convert to numerical values - and possibly translate them back later.</p>

<p><a href="https://i.stack.imgur.com/MLATh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MLATh.png" alt="enter image description here"></a></p>
