CSV - Header Addition

I Have a CSV File in which there will be 3 columns and ’ n ’ number of rows. I want to add the column’s header for one of the columns. Can Anyone suggest me how we can achieve the same using DataTable Manipulation.?

Hey @Gautham_Pattabiraman!! Welcome to the community!!
I didn’t understand your question very well. Could you elaborate more please?
Do you want to add a new column?

CSVQuestion

Hello,

I Have a CSV File Named “A.CSV”. There are 3 columns and 3 rows (Excluding Headers). I Have data in all the columns. However Column Header is there for Columns “A” and “B” Only.

I want to give the C Column a header namely “Section” Through Uipath DataTable Manipulation.

I only want to add a header for a column. Also attached is the Screenshot for the case.

Hi @Gautham_Pattabiraman

You can refer to the Zip below!

Replicate the same using Read csv and Write Csv!

Add_Data_Headers.zip (8.6 KB)

Regards

1 Like

Hey @Gautham_Pattabiraman !! Assuming you already read your .CSV in a DataTable, just do it like this:

image

dt_input.Columns(1).ColumnName

Hope it helps!

1 Like

a screenshot of the CSV data would help us more. As far we do understand:

  • csv file has frist line the headers, but third column name is missing
  • below are the rows in a format of 3 columns

If we got it right then we can handle as following

  • read in csv as text
  • split text on line breaks into a string array (each item is the line content string)
  • repair / manipulate first line (e.g. concat existing string with delimiter char and 3rd col name)
  • pass it as an input to the generate datatable activity and get back a datatable

As a variation:

  • read in text file, split, skip first line, pass to generate datatable
  • rename the auto generated column names afterwards
2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.