[英]I'm using geocoder to get latitude,longitude and address by giving name of a place.How to iterate over the dataframe column
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.