A Step-by-Step Guide to Creating Python Dataframe Using Pandas.

OFONITECH Data HUB
1 min readMar 20, 2023
Example of a Dataframe
  1. First, import the pandas library:
import pandas as pd

2. Next, create a Python dictionary with the data you want to include in the dataframe. For example:

data = {'name': ['Alice', 'Bob', 'Charlie', 'David'],
'age': [25, 30, 35, 40],
'country': ['USA', 'Canada', 'France', 'UK']}

3. Use the pd.DataFrame() function to create a dataframe from the dictionary:

df = pd.DataFrame(data)

4. You can view the dataframe using the .head() function to see the first few rows:

print(df.head())

This should output:

name  age country
0 Alice 25 USA
1 Bob 30 Canada
2 Charlie 35 France
3 David 40 UK

5. That’s it! You now have a Python dataframe with your data. You can access and manipulate the data using pandas functions and methods.

If this short article was helpful, don’t forget to give your thoughts and claps!

Follow me on other social media:

Twitter: https://twitter.com/ofonmbu02472716?t=dS2dG5QszeCOXCqkBh-rVA&s=09

Linkedin: https://www.linkedin.com/in/ofonmbuk-ekanem-a719581b6

Medium: https://medium.com/@brinoekanem

Reddit: https://www.reddit.com/u/OFONITEX

Youtube: https://youtube.com/channel/UCr1It-52cF82k0cWju8ra-g

Discord: Brinoekanem#0848

Telegram: @Brino5

--

--

OFONITECH Data HUB

Process Engineer. Data Analyst. Works with Python, SQL, Excel, Power BI ; Follow and subscribe to get notified of new articles. brinoekanem@gmail.com