[PYTHON] When a character string of a certain series is in the Key of the dictionary, the character string is converted to the Value of the dictionary.

What I want to do: When a Series is in the key of the dictionary, convert the value to the value of the dictionary

【original data】 hoge = pd.Series (["3rd", "1st", "5th", "5th", "2nd", "4th"])

[Conversion list] name_lis = {"first time": "01.first", "Second time": "02.second", "Third time": "03.third", "4th": "04.fourth", "5th time": "05.fifth" }

Surround the Series with a map (Thanks to @nkay!)

hoge.map(name_lis)

Enclose Series in a dictionary

hoge.apply(lambda x: name_lis[x])

0 03.third 1 01.first 2 05.fifth 3 05.fifth 4 02.second 5 04.fourth dtype: object

Recommended Posts

When a character string of a certain series is in the Key of the dictionary, the character string is converted to the Value of the dictionary.
Get the value of a specific key up to the specified index in the dictionary list in Python
Get the value of a specific key in a list from the dictionary type in the list with Python
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
How to quickly count the frequency of appearance of characters from a character string in Python?
When incrementing the value of a key that does not exist
[Python] Execution time when a function is entered in a dictionary value
How to check the memory size of a dictionary in Python
[Golang] Check if a specific character string is included in the character string
What to do when the value type is ambiguous in Python?
In the python dictionary, if a non-existent key is accessed, initialize it with an arbitrary value
[Introduction to Python] Thorough explanation of the character string type used in Python!
I tried to display the altitude value of DTM in a graph
What is the fastest way to create a reverse dictionary in python?
How to input a character string in Python and output it as it is or in the opposite direction.
Python Note: When assigning a value to a string
Isn't there a default value in the dictionary?
To output a value even in the middle of a cell with Jupyter Notebook
Note) Batch conversion of specific symbols contained in a character string with a dictionary
Output timing is incorrect when standard (error) output is converted to a file in Python
How to get the "name" of a field whose value is limited by the choice attribute in Django's model
Check if the string is a number in python
[Python] How to expand variables in a character string
# Function that returns the character code of a string
When a file is placed in the shared folder of Raspberry Pi, the process is executed.
[Solution] When inserting "0001" into the column of string in sqlite3, it is entered as "1".
How to store Python function in Value of dictionary (dict) and call function according to Key
[Ansible] Example of playbook that adds a character string to the first line of the file
A memo when checking whether the specified key exists in the defined dictionary with python
How to check in Python if one of the elements of a list is in another list
[VBA] Function to judge whether the character string of UTF-8 file system is 255 or less and function to count UTF-8 character string in bytes
Find out the apparent width of a string in python
The value of meta when specifying a function with no return value in Dask dataframe apply
When converting a string (a-> b) in Python, which is faster, if statement or dictionary type?
I tried to create a Python script to get the value of a cell in Microsoft Excel
Find out how many each character is in the string.
Extract the value of dict or list as a string
How to turn the for statement when there are multiple values for one key in the dictionary
Is there a secret to the frequency of pi numbers?
How to connect the contents of a list into a string
Write a script in Shell and Python to notify you in Slack when the process is finished
Summary of character string format in Python3 Whether to live with the old model or the new model
Put the process to sleep for a certain period of time (seconds) or more in Python
How to put the string JSON passed as a parameter into the dictionary when writing Ansible module
When you want to replace multiple characters in a string without using regular expressions in python3 series
A simple reason why the return value of round (2.675,2) is 2.67 in python (it should be 2.68 in reality ...)
Output the key list included in S3 Bucket to a file
How to determine the existence of a selenium element in Python
To make sure that the specified key is in the specified bucket in Boto 3
Behavior when 0, 1, False, True is used for the dictionary (dict) key
[Introduction to Python] How to split a character string with the split function
[Introduction to Python] How to output a character string in a Print statement
How to check the memory size of a variable in Python
Delete a particular character in Python if it is the last
How to judge that the cross key is input in Python3
Timezone specification when converting a string to datetime type in python
How to find the memory address of a Pandas dataframe value
How to get the vertex coordinates of a feature in ArcPy
How to extract the desired character string from a line 4 commands
Create a function to get the contents of the database in Go
Is it a character string operation?