How to use 'pandas select row by index' in Python

Every line of 'pandas select row by index' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
525def get_selection_by_index(df, position, orientation='side'):
526 '''
527 Grabs and returns a single column or row.
528 example: myrow = get_selection_by_index(mydf, 2, 'side')
529 grabs row 2 from df.
530 '''
531
532 if orientation == 'side':
533 #will return a single row
534 df = df.ix[[position],:]
535 else:
536 #will return a single col
537 df = df.ix[:,[position]]
538
539 return df
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

74def _select(a, indexes):
75 return [h for h, i in zip(a, range(len(a))) if i in indexes]

Related snippets