I have to filter .csv column and then have to delete some data and unfilter it.
I will get the different numbers every time. (1,2,3 or 40,41,42 Likewise)
I will have to keep the data for last number and have to delete the data by filtering first two 22,23.
FYI- Columns are sorted before this step in ascending order so, each time need to pick the last number which is largest among the three.
Can someone help me here ?
Hi @PALKUMARI_PATEL
Below are the steps with the example data as
You should read the CSV first with Tab as delimiter which will return you a Datatable
And then Try finding the largest number from the column by below linq query
InputDT.AsEnumerable().Max(Function(row) cint(row(“Marks”)))
Finally you can filter the datable with the largest value which you got using
InputDT.AsEnumerable().Where(Function(x) x(Cint(“Marks”)).Equals(MaxValue)).CopyToDataTable()
which gives you the datable containing only with the required largest value.
Cheers,
Happy Automation
Thanks for the detailed explanation but I want to delete the data for other two numbers and then have to keep it only largest. Can you explain that delete code of other two number rows ?
Thanks again in advanced.
As you say already it is sorted…you can use this
say the data is read into datatable dt then
dt.AsEnumerable.GroupBy(function(x) x("NumberColumn").ToString).Last.CopyToDataTable
after this just write the datatable back to csv
cheers
Thanks @Anil_G I don’t know if this will return largest number data and copy the same into that file. Can you explain more ?
As the data is already sorted…I am taking the group by of the column containing numbers and then getting the last group only…and leaving all other groups…as its the last group the data that is retained would be the highest number
And writing only that last group to cav so that all other data is removed
Cheers
Ok, I tried this and it executed without error but when I open that csv it says you can not open the file. Nothing else coming up.
I use read csv then assign activity and providing the same string as you said and write csv.
I am doing it same way. I don’t know what is the error.
@PALKUMARI_PATEL
Once you get the datatable with the required data, you can write it back to CSV using “Write CSV” activity
Yes, @Anil_G I am giving extension also.
Just to check can you give any dummy name and see if you are getting the same issue, instead of rewriting
cheers
You want me to paste the data in any other file with some other name ?
So, IF I write data into other file, It is working and allow to open the file. But It it printing the shortest number as I am sorting in descending order. (My apologies I said Ascending). Can you help me to get the largest number among 3 ?
It is showing in ascending order when I open the filter but actually data is sorted in descending.
Instead of last use first
dt.AsEnumerable.GroupBy(function(x) x("NumberColumn").ToString).First.CopyToDataTable
cheers
Thanks @Anil_G But anything you can suggest me if I want to write the data in same file and I can open it?