# How To Iterate Over Rows In A Dataframe In Pandas

But if one has to loop through dataframe, there are mainly two ways to iterate rows.

- iterrows()
- itertuples()

Let us download a following CSV data from the given link.

In [1]:

```
!wget http://faculty.marshall.usc.edu/gareth-james/ISL/College.csv
```

In [2]:

```
import pandas as pd
import time
```

In [3]:

```
df = pd.read_csv('College.csv')
```

In [4]:

```
df.head(1)
```

Out[4]:

In [5]:

```
len(df)
```

Out[5]:

There are 777 rows in our dataframe.

## Loop through dataframe using iterrows()

In [6]:

```
st = time.time()
for index, row in df.iterrows():
i,r = index,row['Apps']*1
end = time.time()
```

In [7]:

```
print(end-st)
```

## Loop through dataframe using itertuples()

In [8]:

```
st = time.time()
for row in df.itertuples():
apps = row.Apps*1
end = time.time()
```

In [9]:

```
print(end-st)
```

## Loop through dataframe using apply()

In [18]:

```
st = time.time()
df['Apps'] = df.apply(lambda x: x['Apps']*1,axis=1)
end = time.time()
```

In [20]:

```
print(end-st)
```

## Related Notebooks

- How to Export Pandas DataFrame to a CSV File
- How To Drop One Or More Columns In Pandas Dataframe
- How To Write DataFrame To CSV In R
- Pandas How To Sort Columns And Rows
- How to Convert Python Pandas DataFrame into a List
- How to Plot a Histogram in Python
- How to Sort Pandas DataFrame with Examples
- Select Pandas Dataframe Rows And Columns Using iloc loc and ix
- A Study of the TextRank Algorithm in Python