Use [groupby][1] and [sample][2]: import geopandas as gpd import os output_folder = r"/home/bera/Desktop/GIStest/csvs/" df = gpd.read_file(r"/home/bera/Desktop/GIStest/10k_points_wgs84.shp") #Calculate lat and long columns df["lat"] = df.apply(lambda x: x.geometry.y, axis=1) df["lon"] = df.apply(lambda x: x.geometry.x, axis=1) sample_size = 6 for dn, subframe in df.groupby("DN"): #For each DN value. #dn variable is now the value of dn, and subframe is a dataframe with all rows with that dn value print(dn) filename = f"DN_{dn}.csv" #Create an output filename filename = os.path.join(output_folder, filename) subframe.sample(n=sample_size).to_csv(filename, sep=";") [![enter image description here][3]][3] If you want all samples in one file you can use concat: samples = [] #A list to hold each sample data frame for dn, subframe in df.groupby("DN"): #For each DN value. samples.append(subframe.sample(n=sample_size)) result = gpd.pd.concat(samples) #result.to_csv... [1]: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html [2]: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sample.html [3]: https://i.sstatic.net/SDz9D.png