从数据框的字典类型中提取值?

发布于 2025-02-14 02:21:42 字数 761 浏览 23 评论 0原文

我当前的数据框架看起来像这样:

      ID       Date            Data
00112   11-02-2014        {'address1': '161 Glensford Dr', 'address2': '', 'address3': '', 'city': 'Fayetteville', 'zip_code': '28314', 'country': 'US', 'state': 'NC', 'display_address': ['161 Glensford Dr', 'Fayetteville, NC 28314'], 'cross_streets': ''}
00112   11-02-2014       {...}
00112   30-07-2015       {...}
00112   30-07-2015       {...}

我想访问列数据并获取“ adverse1”的所有行的值 对于此数据列,我的所有行都具有相同的格式:

{'address1': '1909 Skibo Rd', 'address2': '', 'address3': '', 'city': 'Fayetteville', 'zip_code': '28314', 'country': 'US', 'state': 'NC', 'display_address': ['1909 Skibo Rd', 'Fayetteville, NC 28314'], 'cross_streets': ''}

我没有如何获取每行地址1的值。

My current data frame looks like this:

      ID       Date            Data
00112   11-02-2014        {'address1': '161 Glensford Dr', 'address2': '', 'address3': '', 'city': 'Fayetteville', 'zip_code': '28314', 'country': 'US', 'state': 'NC', 'display_address': ['161 Glensford Dr', 'Fayetteville, NC 28314'], 'cross_streets': ''}
00112   11-02-2014       {...}
00112   30-07-2015       {...}
00112   30-07-2015       {...}

I would like to access to the column Data and get the value for all my rows of "address1"
I have the same format for all my rows for this Data column:

{'address1': '1909 Skibo Rd', 'address2': '', 'address3': '', 'city': 'Fayetteville', 'zip_code': '28314', 'country': 'US', 'state': 'NC', 'display_address': ['1909 Skibo Rd', 'Fayetteville, NC 28314'], 'cross_streets': ''}

I do not how to get the value of address1 for each row.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2025-02-21 02:21:42

首先通过数据列的行循环循环:

for idx, row in df.iterrows():

然后使用标准字典get函数获取字典中的数据:

print(idx, row['Data'].get("address1"))

因此,它只是2行:

for idx, row in df.iterrows():
    print(idx, row['Data'].get("address1"))

编辑:如果您已经有分配给正确列的系列:

series = df["Data"]
for idx, each in series.iteritems():
    print(idx, each.get("address1"))

Start by looping through the rows of the Data column:

for idx, row in df.iterrows():

Then get the data from dictionary using the standard dictionary get function:

print(idx, row['Data'].get("address1"))

So it's just 2 lines:

for idx, row in df.iterrows():
    print(idx, row['Data'].get("address1"))

Edit: if you already have a series assigned to the correct column:

series = df["Data"]
for idx, each in series.iteritems():
    print(idx, each.get("address1"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文