Remap Values-dict To Columns In Pandas
I have a dataframe where values of features-column are dict-like as here: http://screencast.com/t/0Ko0NIBLwo features name price rating read rev
Solution 1:
I think you can use replace
and strip
and concat
:
print df
features name price \
0 {u'Cooking Type': u'- Specialty Cooking', u'Co... Master Chef1 $279.99
1 {u'Cooking Type': u'- Specialty Cooking', u'Co... Master Chef3 $279.99
rating read reviews
0 None None {}
1 None None {}
df1 = pd.DataFrame([x for x in df['features']], index=df.index)
for col in df1.columns:
df1[col] = df1[col].str.replace(r'-','').str.strip()
print df1
Brand Name Cooking Area Cooking Type Fuel Type Product Type \
0 Pizzacraft Backyard Specialty Cooking Propane BBQ
1 Pizzacraft Backyard Specialty Cooking Propane BBQ
Size
0 Medium Size
1 Medium Size
df = pd.concat([df1, df[['name','price','rating','read','reviews']]], axis=1)
print df
Brand Name Cooking Area Cooking Type Fuel Type Product Type \
0 Pizzacraft Backyard Specialty Cooking Propane BBQ
1 Pizzacraft Backyard Specialty Cooking Propane BBQ
Size name price rating read reviews
0 Medium Size Master Chef1 $279.99 None None {}
1 Medium Size Master Chef3 $279.99 None None {}
Post a Comment for "Remap Values-dict To Columns In Pandas"