Skip to content

Instantly share code, notes, and snippets.

@DavidEWarrenPhD
Forked from chrisgorgo/namedtuple_pandas1.py
Last active November 9, 2020 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidEWarrenPhD/d01d4471f1788f1e810567b015f8a1ad to your computer and use it in GitHub Desktop.
Save DavidEWarrenPhD/d01d4471f1788f1e810567b015f8a1ad to your computer and use it in GitHub Desktop.
NamedTuple + pandas
import pandas as pd
from collections import namedtuple
class Employee(NamedTuple):
name: str
id: int
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.from_records(employees, columns=Employee._fields)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment