Last active
February 11, 2022 04:21
-
-
Save kvnkho/683a5a4dc5cd26798dd58d5de5411065 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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