2808 explained code solutions for 75 technologies


python-pandasGet first 10 rows (head) from data frame


import pandas as pd

data = pd.DataFrame({
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, 404, 405, 305]
})

rows = data.head(10)ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.head(

returns first given amount of rows

(10)

return first 10 rows

rows

will contain selected rows


Usage example

import pandas as pd

data = pd.DataFrame({
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, 404, 405, 305]
})

rows = data.head(10)
print(rows)
output
  Phone  Phone Price
0   ip5          204
1   ip6          304
2   ip8          404
3   sms          405
4    xi          305