51452/splitting-a-column-with-multiple-values-in-python
I want to split a column in a dataframe in python. The column is like:
col_name UO1 UO1,UO2,UO3 UO1,UO2,UO3,UO4,UO5 UO1,SO1,SO3 SO3,UO1
How do I split them as row values?
Try using the following:
df['id'] = df.index+1 df.set_index('id').col_name.str.split(',', expand = True).stack().reset_index(1, drop = True).reset_index(name = 'symptoms') id symptoms 0 1 UO1 1 2 UO1 2 2 UO2 3 2 UO3 4 3 UO1 5 3 UO2 6 3 UO3 7 3 UO4 8 3 UO5 9 4 UO1 10 4 SO1 11 4 SO3 12 5 SO3 13 5 UO1
Actually in later versions of pandas this ...READ MORE
Here's a generator that yields the chunks ...READ MORE
Just replace and with , and you're done: with open('a', 'w') as ...READ MORE
abc.to_json(orient='records') This command will give you the desired ...READ MORE
key error. I love python READ MORE
Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE
There is actually a replace function in ...READ MORE
Try virtualenv : http://pypi.python.org/pypi/virtualenv This helps you create isolated ...READ MORE
In this case, you can use the ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.