Login to pd.read_clipboard()
Ratanhia ,30c x2, 200c x2 Aloe ,30c x2, 200c x2 Nitric Acid ,30c x2, 200c x 2 Sedum Acre ,200c x2, 30c x2 Paeonia ,200c x2, 30c x2 Sulphur ,200c x2, 30c x2 Hamamelis ,30c x1, 200c x1 Aesculus ,30c x1, 200c x1
code:
import pandas as pd df = pd.read_clipboard(header=None, sep=',') df.columns = ['Medicine','power30c','power200c'] df.power30c=df.power30c.apply(lambda x: x[-1]) df.power200c=df.power200c.apply(lambda x: x[-1]) print df
Output:
Medicine power30c power200c 0 Ratanhia 2 2 1 Aloe 2 2 2 Nitric Acid 2 2 3 Sedum Acre 2 2 4 Paeonia 2 2 5 Sulphur 2 2 6 Hamamelis 1 1 7 Aesculus 1
Questions:
- Why is this
on the last line? - How to change more than 1 column in 1 row?
df[['power30c','power200c']] = df[['power30c','power200c']].apply(lambda x: x[-1]) Throws error: ValueError: Length mismatch: Expected axis has 1 elements, new values have 3 elements
Python Version: 2.7, Pandas: 0.19, IPython: 4
source share