I have the following code in which I access a CSV file with multiple columns containing numbers and want to change a specific column under certain conditions:
import csv
import pandas
final_activities = pandas.read_csv("VPN2/VPN2_Final_Activities.csv", delimiter=';', names=['Timerels', 'ActivityClass_Ankle', 'ActivityClass_Hip', 'ActivityClass_Thigh', 'ActivityClass_Wrist', 'ActivityClass_Annotation'], skip_blank_lines=True, skipinitialspace=True, engine='python', header=0)
i = 0
while i < len(final_activities):
ankle_activity = final_activities.loc[i][1]
annotation_activity = final_activities.loc[i][5]
if(int(annotation_activity) == 9 and int(ankle_activity) == 2):
final_activities.at[i, 'ActivityClass_Ankle'] = 9
i += 1
In this case, nothing is being modified in the final_activities
DataFrame due to the .at
statement. It used to work for me before. Please help!