1

I have been sent a file. I have read it in as a dataframe which contains only one column and over a 1,000,000 rows. Each row is a mixture of numbers and text.

I tried the following line below.

data = data.str.split('/t',expand=True)

However I get the error below,

AttributeError: 'DataFrame' object has no attribute 'str'

I thought maybe it was because its of type object and not string. So tried the line below however that seems to have no effect.

data.astype('str')

How can I split this column?

1 Answer 1

1

I think there is one column DataFrame, so for one column is possible select first column by position with DataFrame.iloc:

data = data.iloc[:, 0].str.split('/t',expand=True)

Or if psosible select first column by name:

data = data['col'].str.split('/t',expand=True)
Sign up to request clarification or add additional context in comments.

3 Comments

using the first suggestion just seems to have changed the column name from some long horrible name to 0. I didn't try the second as the column name is so long
@mHelpMe - Are you sure? Because 0 here means first column of data
sorry it is now working, just re-ran it and indeed it worked, thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.