Reputation: 7265
Here's my data:
Id var_map
1 {'email_count': 3.0, 'outgoing': 90.0}
2 {'Email_Count': 5.0, 'outgoing': 91.0}
What I did is
df['var_map'] = score_data['var_map'].str.lower()
The result is different with why I expected, the error is are this
Id var_map
1 NaN
2 NaN
How do I suppose to solve this
Upvotes: 0
Views: 671
Reputation: 88
def var_map_lower(var_map):
return {x.lower(): y for (x,y) in var_map.items()}
df['var_map'] = df['var_map'].apply(var_map_lower)
Can you try this?
Upvotes: 0
Reputation: 2116
Have you tried converting data column to string?
import pandas as pd
data['var'] = data['var_map'].astype(str).str.lower()
print data
Upvotes: 3
Reputation: 82785
This is one approach using apply
.
Ex:
import pandas as pd
df = pd.DataFrame({"var_map": [{'email_count': 3.0, 'outgoing': 90.0}, {'Email_Count': 5.0, 'outgoing': 91.0}]})
df["var_map"] = df["var_map"].apply(lambda x: {k.lower(): v for k,v in x.items()})
print(df)
Output:
var_map
0 {u'outgoing': 90.0, u'email_count': 3.0}
1 {u'outgoing': 91.0, u'email_count': 5.0}
Upvotes: 3