2 identical columns in a csv

I am having 2 identical columns in a csv with same names and same records. I want to remove 1 of the column. But I am not able to read csv. It just throws an exception and can’t even read csv. Any solution?

Make a new datatable, but only add the columns you want to keep ?

For example if i had this csv ( OriginalDT) :

[Name] [Age] [Age]
Zak 32 32
Mika 29 29

then i would make a new DT :

Activities -. New datatable → add column headers “Name” and “Age” → newDT

Then do the following :

“For each row in [ OriginalDT ]”

Get row item - Column index [1] , Row item [row] to variable “Name”

get row item - column index [2], Row item [row] to variable “Age”

now that i have the 2 items i want,

Add data row → { Name, Age } to newDT

save newDT to CSV.

Result =

[Name] [Age]
Zak 32
Mika 29

Here is a working example of the above.

remove column.zip (3.1 KB)

The csv’s that I am getting are with dynamic columns so I can’t build datatable as I don’t know what the column names are.
Also I am not able to even read the csv’s with 2 identical column names. If I am able to read, only then I can think of performing some operations on it.

In the csv activity, try unchecking “include Column names”. I had to do this to open my example csv as it won’t read a csv with 2 column names that are the same.

I then worked off the column indexes and added the column names to the datatable.

Thanku so much. It worked for now. But what I needed was something else.

I dont know the column names and column indexes. I am getting CSV’s with different column names.

I must apologise, that’s not something I can help with ( I’m a rookie myself ).

1 Like

No problem.:+1:
Will see if someone else could help me with this.

Hi @Mukesh_Ahuja

Given that .csv files are simple text files, you can read it with Read Text activity and then use a Generate Data Table activity to turn your data into a Data Table with generic, but unique column names.
You can then process your data as you wish.

See attached workflow for reference:
Reading CSV.zip (2.6 KB)

1 Like