Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import modules
- import pandas as pd
- # import dataframe from .csv
- data = pd.read_csv("./data.csv")
- # create empty dataframe for output
- columnNames = ['user', 'trial', 'reaction_time']
- newData = pd.DataFrame(columns=columnNames)
- processedTrials = [] # used to mark trials that have been processed
- currentUser = 0 # the current user being processed
- for index, row in data.iterrows():
- print("Processing row ", index, "...")
- # if processing a new user, clear the list of processed trials and assign new user as current
- if row['user'] != currentUser:
- currentUser = row['user']
- processedTrials = []
- # if selected trial has already been processed, skip
- if row['trial'] in processedTrials:
- print("Skipping row")
- continue
- # otherwise, save data to new dataframe
- else:
- print("Appending data...")
- processedTrials.append(row['trial'])
- newData = newData.append({'user':row['user'], 'trial':row['trial'], 'reaction_time':row['\'reaction_time_2\'']}, ignore_index=True)
- # print sample of output and save to .csv
- print(newData.head())
- newData.to_csv('./newData.csv', index=False, encoding='utf-8')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement