How to collect a data from a csv file using a specific Id?
Question:
I want to iterate 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 iterate through the each cells in the field one at a time.
Answers:
What about giving an extra loop outside and give
x = int(input('number of rows to be retrieved')) #to receive first x rows
for i in range(0,x):
#give your code here
in which give value[i]
just try this method. hope this works.
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.
x = int(input('number of rows'))
for y in range(0,x):
in which give value[y]
x = int(input(‘number of rows’))
for y in range(0,x):
in which give value[y]
Hope this works
I want to iterate 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 iterate through the each cells in the field one at a time.
What about giving an extra loop outside and give
x = int(input('number of rows to be retrieved')) #to receive first x rows
for i in range(0,x):
#give your code here
in which give value[i]
just try this method. hope this works.
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.
x = int(input('number of rows'))
for y in range(0,x):
in which give value[y]
x = int(input(‘number of rows’))
for y in range(0,x):
in which give value[y]
Hope this works