Instagram
youtube
Facebook
Twitter

Create a Pandas DataFrame with Columns 'Name', 'Age', 'Gender', and 'City'

Create a Pandas DataFrame with Columns 'Name', 'Age', 'Gender', and 'City'
     
Short Description of the Program:

This program creates a Pandas DataFrame using a dictionary that includes columns 'Name', 'Age', 'Gender',       and 'City'.

Explanation:

  • import pandas as pd
    Imports the pandas library using the alias pd.

     
  • data = {...}
    A dictionary where keys are column names and values are lists of data.

     
  • pd.DataFrame(data)
    Converts the dictionary into a structured tabular format.

     
  • print(df)
    Prints the resulting DataFrame.

Program:

import pandas as pd

data = {

    'Name': ['Alice', 'Bob', 'Charlie', 'Diana'],

    'Age': [25, 30, 22, 28],

    'Gender': ['Female', 'Male', 'Male', 'Female'],

    'City': ['New York', 'Los Angeles', 'Chicago', 'Houston']

}
df = pd.DataFrame(data)

print(df)