CSV manipulation

This is quite a convoluted problem. Ultimately, I need users to be able to upload a csv that adds further row to a data type, but the csv needs some manipulation before the data can be added. This is what needs to happen (the csv is in no way formatted to make life easy - exported from an online service), and in this order…

  • Remove the first two rows (column headers start on row three)
  • Some columns don’t have a header. Specify their name automatically
  • Delete a column
  • Concatenate two columns into one to make a new column with a set field name
  • The data is five days of events, in a row, with the date of the events for each set of 8 columns in a cell above the column headers. Ideally the data for day two would move to new rows, with the identifiers repeated again.

The last point is quite hard to explain, but ultimately I’d like to get from this…


…to this…
002
…or at least this…

…without the user having to manipulate the original file.

Any help would be massively appreciated.