27
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.
Lets get practical. We will be doing the following.
- Get a few python list
- Set up the data in clean way
- Export the data to an excel sheet
Lets take some random data. We will make two list number and email
number = []
email = []
data = [
{
'numberrange': "53262",
'email':'[email protected]',
},
{
'numberrange': "553343",
'email': "[email protected]"
},
{
'numberrange': "638442",
'email': "[email protected]"
},
{
'numberrange': "75523",
'email': "[email protected]"
},
{
'numberrange': "66493",
'email': "[email protected]"
}
]
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'])
import pandas as pd
number = []
email = []
data = [
{
'numberrange': "53262",
'email':'[email protected]',
},
{
'numberrange': "553343",
'email': "[email protected]"
},
{
'numberrange': "638442",
'email': "[email protected]"
},
{
'numberrange': "75523",
'email': "[email protected]"
},
{
'numberrange': "66493",
'email': "[email protected]"
}
]
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)
27