How do I map tuples in Python using pandas?

Python, Pandas, Tuples, Data Mapping, DataFrame
Learn how to map tuples in Python using the Pandas library to efficiently manipulate and analyze your data.
import pandas as pd # Sample data data = { 'A': [(1, 'apple'), (2, 'banana'), (3, 'cherry')], 'B': [(4, 'date'), (5, 'fig'), (6, 'grape')] } # Creating DataFrame df = pd.DataFrame(data) # Mapping tuples in column 'A' to a new column 'C' df['C'] = df['A'].apply(lambda x: x[1]) # Extracting the second element of each tuple print(df)

Python Pandas Tuples Data Mapping DataFrame