Skip to main content

/docs/images/banner.png

Python

pandas dataframe

Write a Python script that uses the Pandas library to create a DataFrame from a given dictionary and display the resulting DataFrame

import pandas as pd

data = {
'Name': ['John', 'Jane', 'Sue', 'Fred'],
'Age': [23, 29, 21, 18],
}

df = pd.DataFrame(data)
print(df)

# Output:
# Name Age
# 0 John 23
# 1 Jane 29
# 2 Sue 21
# 3 Fred 18
note

To compile and run the program, you can use the following commands:

python3 foo.py