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

2024-06-16 15:44:10 发布

您现在位置:Python中文网/ 问答频道 /正文

为我最后一年的项目做一个计划。 该程序从.csv数据集中获取经度和纬度坐标,并将其绘制在地图上。 我遇到的问题是有多个ID,总计445000+分

我如何改进它,使程序能够区分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)

我还附加了程序工作的github project here,但我只是想尽量减少它一次打印多少用户

提前谢谢


1条回答
网友
1楼 · 发布于 2024-06-16 15:44:10

要检查特定ID,可以创建一个筛选器。对于此数据帧

    long    lat     ID
0   10      5       test1
1   15      20      test2

您可以执行以下操作:

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

这可用于从数据帧中筛选出ID为“test1”的每个条目

df_data[id_filt]


long    lat     ID
10      5       test1

相关问题 更多 >