简体   繁体   English

从 python 中的 csv 数据集中提取 ID 和相关数据

[英]Extracting ID and Relevant data from a csv dataset in python

Making a program for my Final Year Project.为我的最后一年项目制作程序。 Program takes the longitude and latitude coords from a.csv dataset and plots them on the map.程序从 a.csv 数据集中获取经度和纬度坐标,并将它们绘制在 map 上。 Issue I am having is there is multiple ID's and this totals 445,000+ points.我遇到的问题是有多个 ID,总计 445,000+ 点。

How would I refine it so the program can differentiate between the IDs?我将如何改进它以便程序可以区分 ID?

 def create_image(self, color, width=2):
    # Creates an image that contains the Map and the GPS record
    # color = color the GPS line is
    # width = width of the GPS line
    data = pd.read_csv(self.data_path, header=0)
    # sep will separate the latitude from the longitude
    data.info()
    self.result_image = Image.open(self.map_path, 'r')
    img_points = []
    gps_data = tuple(zip(data['latitude'].values, data['longitude'].values))

    for d in gps_data:
        x1, y1 = self.scale_to_img(d, (self.result_image.size[0], self.result_image.size[1]))
        img_points.append((x1, y1))
    draw = ImageDraw.Draw(self.result_image)
    draw.line(img_points, fill=color, width=width)

I have also attached the github project here the program works but I am just trying to minimize how many users it plots at once.我还在此处附加了 github 项目,该程序可以正常工作,但我只是想尽量减少它一次绘制的用户数量。

Thanks in advance.提前致谢。

To check for a specific ID you could create a filter.要检查特定 ID,您可以创建一个过滤器。 For this dataframe对于这个 dataframe

    long    lat     ID
0   10      5       test1
1   15      20      test2

you could do the following:您可以执行以下操作:

id_filt = df_data['ID'] == 'test1'

This can be used to filter out every entry from the dataframe that has the ID 'test1'这可用于过滤掉 dataframe 中 ID 为“test1”的每个条目

df_data[id_filt]


long    lat     ID
10      5       test1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM