Reputation: 105
I have a pandas dataframe of the following format.
0 06-10-2000 Deposit $40.00
1 09-12-2002 Withdraw $1000.00
2 27-06-2001 Deposit $47.00
3 07-12-2021 Withdraw $100.00
4 06-10-2022 Deposit $120.00
5 06-10-2000 Deposit $40.00
6 09-12-2024 Withdraw $50.00
How do I split each row in to 3 columns. Ideal output wanted:
Date Status Amount
0 06-10-2000 Deposit $40.00
1 09-12-2002 Withdraw $1000.00
2 27-06-2001 Deposit $47.00
3 07-12-2021 Withdraw $100.00
4 06-10-2022 Deposit $120.00
5 06-10-2000 Deposit $40.00
6 09-12-2024 Withdraw $50.00
Upvotes: 0
Views: 35
Reputation: 153460
You can use named groups and extract
:
df[1].str.extract('(?P<Date>.*) (?P<Status>.*) (?P<Amount>.*)')
Output:
Date Status Amount
0 06-10-2000 Deposit $40.00
1 09-12-2002 Withdraw $1000.00
2 27-06-2001 Deposit $47.00
3 07-12-2021 Withdraw $100.00
4 06-10-2022 Deposit $120.00
5 06-10-2000 Deposit $40.00
6 09-12-2024 Withdraw $50.00
Upvotes: 2
Reputation: 34056
Assuming the separator in the column is a whitespace
, you can use str.split
with expand=True
:
df[['col1','col2','col3']] = df['column'].str.split(expand=True)
Upvotes: 1