简体   繁体   English

我正在使用地理编码器通过给出地点的名称来获取纬度,经度和地址。如何在数据框列上进行迭代

[英]I'm using geocoder to get latitude,longitude and address by giving name of a place.How to iterate over the dataframe column

I'm using geocoder to get latitude,longitude and address by giving name of a place.How to iterate over the dataframe column 我正在使用地理编码器通过给出地点的名称来获取纬度,经度和地址。如何在数据框列上进行迭代

code to calculate latitude and longitude of place name when defined: 定义时计算地名纬度和经度的代码:

在此处输入图片说明

To make it easy and understandable you could have shown the head of your Dataframe to see the columns. 为了使它容易理解,您可以显示数据框的标题以查看各列。

to itegrate through a dataFrame: 通过dataFrame进行重新定义:

for column in df:
    print(df[column])

or you can use iteritems() 或者你可以使用iteritems()

for name, values in df.iteritems():
    print('{name}: {value}'.format(name=name, value=values[0]))

Another workaround is to transpose the DataFrame and iterate over the rows. 另一个解决方法是转置DataFrame并在行上进行迭代。

for column_name, column in df.transpose().iterrows():
    print(column_name)

We can use Python's list slicing easily to slice df.columns according to our needs. 我们可以根据需要轻松使用Python的列表切片对df.columns进行切片。 For eg, to iterate over all columns but the first one, we can do: 例如,要遍历除第一列之外的所有列,我们可以这样做:

for column in df.columns[1:]:
    print(df[column])

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

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