You're given two lists the first of which contains the name of some people and the second contains their corresponding 'response'.

You're given two lists, the first of which contains the name of some people and the second contains their corresponding 'response'. These lists have been converted to a dataframe.

Now, the values that the 'response' variable can take are ‘Yes’, ‘No’, and ‘Maybe’. Write a code to map these variables to the values ‘1.0’, ‘0.0’, and ‘0.5’.

Note: It also might happen the the first letter of the three responses are not in uppercase, i.e. you might also have the values 'yes', 'no', and 'maybe' in the dataframe. So make sure you handle that in your code.

Example

Input 1:

['Reetesh', 'Shruti', 'Kaustubh', 'Vikas', 'Mahima', 'Akshay']
['No', 'Maybe', 'yes', 'Yes', 'maybe', 'Yes']

Output 1:

You're given two lists, the first of which contains the name of some people and the second contains their corresponding 'response'. These lists have been converted to a dataframe.

Python Pandas Solution

import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)

name = input_list[0]
response = input_list[1]

import pandas as pd 
df = pd.DataFrame({'Name': name,'Response': response})

def response_map(x):
    return x.map({'Yes': 1, 'yes': 1, 'No': 0, 'no': 0, 'Maybe': 0.5, 'maybe': 0.5})

df[['Response']] = df[['Response']].apply(response_map)

print(df)

Comments