Skip to content

Instantly share code, notes, and snippets.

@chrisgorgo
Last active November 9, 2020 17:31
Show Gist options
  • Save chrisgorgo/a971a91ffe1ae05974c8eff700f38c6f to your computer and use it in GitHub Desktop.
Save chrisgorgo/a971a91ffe1ae05974c8eff700f38c6f to your computer and use it in GitHub Desktop.
namedtuple + pandas
import pandas as pd
from collections import namedtuple
Employee = namedtuple("Employee", "name, id")
employees = []
next_employee = some_api_query("first")
while next_employee:
employees.append(Employee(name=next_employee.first_name + " " + next_employee.last_name,
id=next_employee.id))
next_employee = next_employee.next
employees_df = pd.DataFrame(data=employees)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment