OK, let me write it in "improvised pseudocode" since you said you only need an idea rather than ready-made solution and I think it'll be more fun for you to implement it yourself:
strings_array[][4]; // dynamic array of arrays; outer array's elements are strings of your CSV file
// and inner array has 4 elements corresponding for time, x, y and z
results_array[][4]; // same type of array to store results: final timestamp of each window
// and respective averages for x, y and z
start_time = strings_array[0][0]; // saving starting time
sum_coord[3] = {0,0,0}; // array to store sum of each of the x, y and z
points_num = 0; // variable to store number of time points in the current window
line_num = 0; // variable to store number of lines processed
while (line_num < strings_array.length) { // iterating over outer part of strings_array - i.e. over
// lines of original CSV file
string_arr = strings_array[line_num]; // storing current line of CSV file
line_num++; // incrementing total number of lines processed
if (string_arr[0] < start_time+2000) { // if end of the window is not reached yet
for (i=0; i<3; i++)
sum_coord[i] += string_arr[i]; // adding each of x, y and z to the sum of the window
points_num++; // incrementing number of time points in the window
continue; // go to the next line of CSV file
}
// if, on the other hand, we have exceeded the window
// storing averages for the window
if (points_num == 0)
results_array.append({start_time, 0, 0, 0});
else
results_array.append({start_time, sum_coord[0]/points_num, sum_coord[1]/points_num, sum_coord[2]/points_num});
sum_coord = {0, 0, 0}; // resetting each of x, y and z sums of the window
points_num = 0; // resetting number of time points in the window
while (strings_array[line_num-1][0] >= start_time+1000) // going back 1 sec until we find start of the next window
line_num--;
start_time+=1000; // resetting beginning of the window (make sure it's what you mean!)
// otherwise, can do: start_time = strings_array[line_num-1][0]
// to have next window based on the last timepoint within 1 sec
}