How can I read row by row in a Dataframe
using a loop and return each value or pop out each value?
Example:
id name
1 abc
2 vbs
2 askj
Assuming you are using pandas dataframes
You can use iterrows
In [3]: for index, row in df.iterrows():
...: print('Index is: {}'.format(index))
...: print('ID is: {}; Name is: {}'.format(row['id'], row['name']))
...:
Index is: 0
ID is: 1; Name is: abc
Index is: 1
ID is: 1; Name is: vbs
Index is: 2
ID is: 2; Name is: askj
Iterrows is iterating over the index, row tuple. The row here is a Series .
In [4]: type(row)
Out[4]: pandas.core.series.Series
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.