0

Python scrub here and I have an excel spreadsheet I'm importing into my Python script using Pandas and I'm having some issues with the 2D Arrays. Basically, I have the Excel workbook under the variable "workbook", then I'm using the pd.Dataframe command to store only a certain column of data, but I don't understand how I can go down the list of cells one by one in that column? Ultimately, I'm looking to create a loop that will allow me to input each row one at a time, then putting that information into a dictionary, then use that dictionary in a function to automate some data backups.

Workbook = (my excel file path)
eRead = pd.read_excel(workBook, sheet_name = 'Sheet1')
eIP = pd.DataFrame(eRead, columns= ['IP'])

print(eIP) shows the 3 entries + the header of the excel document. I apologize if I didn't explain this correctly but as I stated, I'm still learning.

1 Answer 1

1

Not sure to understand your goal here, but here is one way to iterate on rows:

import pandas as pd

eIP = pd.DataFrame({"IP": ["a", "b", "c"]})

for _, row in eIP.iterrows():
    print(row.values[0])

# Output
a
b
c

You can also get a dictionary of the values like this:

print(eIP.to_dict()["IP"])
# Output
{0: 'a', 1: 'b', 2: 'c'}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.