Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1016 Bytes

how-to-get-dataframe-row-by-index.md

File metadata and controls

46 lines (36 loc) · 1016 Bytes

How 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]
  • import pandas as pd - load lib: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

group: fetch

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.loc[3]
print(row)
Vendor     KR
Phone     sms
Price     405
Used      320
Name: 3, dtype: object