9951 explained code solutions for 126 technologies


python-pandasHow to get row from dataframe by row number


import pandas as pd

data = pd.DataFrame({
  'Vendor': ['US', 'US', 'US', 'KR', 'KR'],
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Price': [204, 304, 102, 405, 350],
  'Used': [150, 250, 80, 320, 280]
})

row = data.iloc[2]ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.iloc[

returns row by given integer position (starts from 0)

[2]

selects 3rd row (index starts from 0)


Usage example

import pandas as pd

data = pd.DataFrame({
  'Vendor': ['US', 'US', 'US', 'KR', 'KR'],
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Price': [204, 304, 102, 405, 350],
  'Used': [150, 250, 80, 320, 280]
})

row = data.iloc[2]
print(row)
output
Vendor     US
Phone     ip8
Price     102
Used       80
Name: 2, dtype: object