Last active
September 8, 2021 16:21
-
-
Save chrisgorgo/2451350bce5e1458ddad731fa4ad4490 to your computer and use it in GitHub Desktop.
NamedTuple + pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(data=employees) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment