Skip to content
Advertisement

How To Assign Different Column Values To Different Variables In Python

I am trying to assign all the three unique groups from the group column in df to different variables (see my code) using Python. How do I incorporate this inside a for loop? Obviously var + i does not work.

JavaScript

Advertisement

Answer

From your comment it seems it is okay for all_vars to be a list so that all_vars[0] is the first group, all_vars[1] the second, etc. In that case, consider using groupby instead:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement