DEV Community

Fabian Anguiano
Fabian Anguiano

Posted on

2 1

Getting started with pandas (practical example) 2021

Pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool,
built on top of the Python programming language.

What does that even mean?

Lets get practical. We will be doing the following.

  1. Get a few python list
  2. Set up the data in clean way
  3. Export the data to an excel sheet

Clean up raw data

Lets take some random data. We will make two list number and email


number = []
email = []

data = [
    {
        'numberrange': "53262",
        'email':'eu@aol.com',
    },
    {
        'numberrange': "553343",
        'email': "non.hendrerit.id@google.ca"
    },
    {
        'numberrange': "638442",
        'email': "donec.tempus.lorem@google.couk"
    },
    {
        'numberrange': "75523",
        'email': "lorem.vitae.odio@aol.org"
    },
    {
        'numberrange': "66493",
        'email': "orci.lacus@aol.edu"
    }
]

Enter fullscreen mode Exit fullscreen mode

Looping the data

Now lets loop the data and get all instances of 'numberrange' and 'email'. We will append the results to our list we made above.

for i in data:
    print(i['numberrange'])
    print(i['email'])
    number.append(i['numberrange'])
    email.append(i['email'])
Enter fullscreen mode Exit fullscreen mode

Putting it all together


import pandas as pd

number = []
email = []




data = [
    {
        'numberrange': "53262",
        'email':'eu@aol.com',
    },
    {
        'numberrange': "553343",
        'email': "non.hendrerit.id@google.ca"
    },
    {
        'numberrange': "638442",
        'email': "donec.tempus.lorem@google.couk"
    },
    {
        'numberrange': "75523",
        'email': "lorem.vitae.odio@aol.org"
    },
    {
        'numberrange': "66493",
        'email': "orci.lacus@aol.edu"
    }
]


for i in data:
    print(i['numberrange'])
    print(i['email'])
    number.append(i['numberrange'])
    email.append(i['email'])



df = pd.DataFrame()

df['Number'] = number
df['Email'] = email



# Converting to excel
df.to_excel('Make_an_excel_sheet.xlsx', index=False)

Enter fullscreen mode Exit fullscreen mode

alt text

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay