What's the use of Pandas map?
Editor to share with you what is the use of Pandas map, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Pandas map
Map is another important operation that provides a high degree of flexibility and practical application.
Pandas map () is used to map each value in the sequence to other values based on the input correspondence. In fact, this input can be a sequence, a dictionary, or even a function.
Let's give an interesting example. We have a virtual employee dataset. This data set consists of the following-name, age, occupation, city.
Now you need to add another column to indicate the corresponding status. What would you do? If the range of the dataset is 10 rows, you can execute it manually, but what if there are thousands of rows? It is more advantageous to use Pandas map.
# sample data data = {'name': [' Aids, 'bones,' cations, 'Downs,' E'], 'age': [22, 26, 33, 44, 50],' profession': ['data engineer',' data scientist', 'entrepreneur',' business analyst', 'self-employed'],' city': ['Gurgaon',' Bangalore', 'Gurgaon',' Pune'] 'New Delhi']} df = pd.DataFrame (data) df# city and state map_city_to_states = {' Gurgaon': 'Haryana',' Bangalore': 'Karnataka',' Pune': 'Maharashtra' 'New Delhi':' Delhi'} # maps city columns to state df ['state'] = df [' city'] .map (map_city_to_states) df above is all the content of the article "what's the use of Pandas map"? Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!