Removing Commas And Unlisting A Dataframe
Background I have the following sample df: import pandas as pd df = pd.DataFrame({'Before' : [['there, are, many, different'], ['i, like, a, lot, of
Solution 1:
As you confirmed, the solution is simple. For one column:
df.After.str[0].str.replace(',', '')
Out[2821]:
0in the bright blue box
1 because they go really fast
2 to ride and have fun
Name: After, dtype: object
For all columns having lists, you need using apply
and assign back as follows:
df.loc[:, ['After', 'Before']] = df[['After', 'Before']].apply(lambda x: x.str[0].str.replace(',', ''))
Out[2824]:
After Before N_ID P_ID Word
0in the bright blue box there are many different A1 1 crayons
1 because they go really fast i like a lot of sports A2 2 cars
2 to ride and have fun the middle east has many A3 3 camels
Post a Comment for "Removing Commas And Unlisting A Dataframe"