9951 explained code solutions for 126 technologies


python-pandasHow to get dataframe row by index


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.loc[3]ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.loc[

returns row by given index

[3]

will select 4th row (indexes start with 0)

row

will contain selected row