3

I'm trying to import the csv file into the Pandas DataFrame. However, here is the challenge, for example, I cannot use skiprows=9, because the csv format is inconsistent from time to time, it will contain some useless information before the actual table begins.

Fortunately, before the table starts, there will always have a single row with the string "report field", and then the real table starts from the next line.

Is there any way I can skip all the rows until it catches the pattern "report field"?

Thanks.

1 Answer 1

1
df= pandas.read_csv("file.csv",header= None)
df_2= df.iloc[(df.loc[df[0]=='report field'].index[0]+1):, :].reset_index(drop = True)

So, the above line searches for "report field" value in "0" column of "df" dataframe and then picks up data from the next row to the last row in the "file.csv" file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.