[Solved] Writing Specific CSV Rows to a Dataframe


I appreciate being downvoted without given reasons why my question deserves a downvote. I was able to figure it out on my own though. Hopefully, this may answer other people’s questions in the future.

    import csv
    import pandas as pd
    temp = []  #initialize array
    with open('C:/Users/sword/Anaconda3/envs/exceltest/RF_SubjP02_Free_STATIC_TR01.csv', 'r') as csvfile:
         csvreader = csv.reader(csvfile, delimiter=",")
         for row in csvreader:
             if csvreader.line_num == 3:  
                temp.append(row)     #gets column names and saves to array  
             if csvreader.line_num >= 6:
                if row: 
                     temp.append(row)  # gets data values and saves to array
                else: #stops at blank row
                     break
    df = pd.DataFrame(temp) #creates a dataframe from an array
    df.columns = df.iloc[0]  #make top row the column names
    df.reindex(df.index.drop(1))
    print(df)

solved Writing Specific CSV Rows to a Dataframe