Skip to content

Instantly share code, notes, and snippets.

@kvnkho
Last active February 11, 2022 04:21
Show Gist options
  • Select an option

  • Save kvnkho/683a5a4dc5cd26798dd58d5de5411065 to your computer and use it in GitHub Desktop.

Select an option

Save kvnkho/683a5a4dc5cd26798dd58d5de5411065 to your computer and use it in GitHub Desktop.
from typing import List, Dict, Any, Iterable
def map_letter_to_food2(df: List[Dict[str,Any]], mapping: Dict) -> Iterable[Dict[str,Any]]:
for row in df:
row["food"] = mapping[row["value"]]
yield row
def map_letter_to_food3(df: List[List[Any]], mapping: Dict) -> List[List[Any]]:
for row in df:
row.append(mapping[row[1]])
return df
def map_letter_to_food4(df: List[List[Any]], mapping: Dict) -> pd.DataFrame:
for row in df:
row.append(mapping[row[1]])
df = pd.DataFrame.from_records(df, columns=["id", "value", "food"])
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment