My apologies if similar questions have been asked -- I dug through quite a few, but they did not match my specific issue.
Basically, I have an Excel spreadsheet with 2 columns; Name and Email. I'm using pandas to grab the two columns from the file. I want to grab the values from the columns in order, and append them to a dictionary so that I can easily reference name and email pairs later on.
I currently have two functions in two files. One is my main file/function, and the other is a file named readExcel with a function named read:
# readExcel.py
import pandas as pd
def read(fileName: str, sheetName: str):
f = pd.read_excel(fileName, sheet_name = sheetName)
return f
# __main__.py
import readExcel as re
from pathlib import Path
def main():
contacts = {}
p = Path(__file__).with_name('contacts.xlsx')
f = re.read(p, "Sheet1")
for n in f["Name"]:
for e in f["Email"]:
contacts[n] = e
print(contacts)
The issue I'm facing here is that the resulting dictionary is un-ordered, e.g., Bob Testerson: jim.tester@gmailcom, Jim Tester: bob.testerson@gmail.com
How would I go about properly ordering the data I'm pulling from the spreadsheet?
EDIT: Per request, I'll add more information regarding the Excel file and preferred order.
The Excel file looks like this: Excel image preview
As for the ordering of the data, it seems it would be best done before adding it to the dictionary, but that's not a requirement for me. Also, I don't specifically care about the order in which the key / value pairs appear in the dictionary, but rather that the key /values pairs appear as they do in the Excel file, e.g.,
{
"Jon Testerson": "jon.test@gmail.com",
"Henry": "henrytest@gmail.com",
"Bryce Testington": "brycetestington@gmail.com",
"Greg": "greg_test@yahoo.com",
"Jerry Testerfield", "jerrytester@hotmail.com"
}