Raghavendra Boina
Raghavendra Boina

Reputation: 65

Distinct column values in csv file

I have a csv file. columns in csv file - "SNo. StateName CityName AreaName PinCode NonServ.Area MessangerService Remark". The column CityName has repeated values.

Ex: In many records, it has unique value (Delhi). Is there any approach in java to read that csv file and get the distinct values from that column of the csv file.

Upvotes: 1

Views: 5092

Answers (2)

user8155912
user8155912

Reputation:

df is where you've read csv data

df[CityName].unique()

Upvotes: 0

kojow7
kojow7

Reputation: 11384

The only way I can think of is to do it row by row and store each value into an array-type structure. Using a set structure such as HashSet or TreeSet will ensure unique values.

The other option, which isn't what you were looking for but might work depending on your project is to use a database instead of a csv file. It then becomes very easy to select distinct values in a column.

Upvotes: 1

Related Questions