I want to Iter through all the fields in the csv file when I call for the data using the specific user ID
for name, values in df.iteritems(): print('{name}: {value}'.format(name=name,value=values[1]))
When I run this code its iterating through the first field then moving to the next. I want it to iter through the each cells in the field one at a time.
You are looking for iterrows
method.
If name
and value
are column names:
for _, row in df.iterrows():
print('{name}:{value}'.format(name=row[0], value=row[1]))
If name
is an index and value
is a column name:
for index, row in df.iterrows():
print('{name}:{value}'.format(name=index, value=row[0]))
iteritems
method has been deprecated, and it was intended to iterate through columns, not rows.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.