Collaborative Filtering

The dataset I am working on has column in text format. Till now I manually assigned them numbers and stored in the dictionary. What can be more better and optimize way to do the same. So that the module become dynamic and can treat any type of dataset. What type of functions and libraries can be used ?