【问题标题】:Extracting ID and Relevant data from a csv dataset in python从python中的csv数据集中提取ID和相关数据
【发布时间】:2021-04-23 13:01:26
【问题描述】:

为我的最后一年项目制作程序。 程序从 .csv 数据集中获取经度和纬度坐标,并将它们绘制在地图上。 我遇到的问题是有多个 ID,总共 445,000+ 点。

我将如何改进它以便程序可以区分 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,该程序可以运行,但我只是想尽量减少它一次绘制的用户数。

提前致谢。

【问题讨论】:

  • 您能否从您的数据框中提供一个 sn-p。 ID 是其中的一部分吗?
  • 这个问题和tkinter有关系吗?我看不到任何与tkinter相关的代码
  • @TheLizzard 抱歉,是的,GUI 正在使用 TKinter,主要执行命令来自 tkinter。
  • @PonyTale 与 .csv 文件中的一样吗?由于ID被称为iPhoneUID。我还没有实现它,因为我不确定如何解决这个问题。我会将数据集添加到 GitHub
  • @JagerScouser 你认为一个人需要知道如何使用tkinter 来解决你的问题吗?据我所知,这个问题可以在几乎不了解 tkinter 的情况下解决。如果我是正确的,请删除tkinter 标签

标签: python pandas numpy csv


【解决方案1】:

要检查特定 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

【讨论】:

    猜你喜欢
    • 2022-06-11
    • 2019-04-03
    • 2015-05-24
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    相关资源
    最近更新 更多