0

I apologize in advance if this is a dumb/obvious question, I'm basically brand new to coding.

I just want to take a column of numbers I have in an excel file and append it to a list/dictionary

I've figured out how to print my excel file using the following code:

import pandas as pd

file = r'C:\Users\Me\sampleData.xlsx'
df = pd.read_excel(file, engine='openpyxl')
print(df)

The "sampleData" file is a single column of twenty random integers between 1 and 100.

Is there a way to make a list/dictionary of the values I have in my excel file?

David Erickson
  • 16,433
  • 2
  • 19
  • 35
  • 1
    You mean list - not dictionary? For a `list` use `df.values.tolist()` If you want to make a dictionary what is the key and value? Dictionaries have pairs of key and value that map to each other. If you want a `dict`, then it depends, but you can use `.df.to_dict()`; however, there are different parameters that you can pass depending on desired output. – David Erickson Dec 23 '20 at 20:54
  • @DavidErickson Sorry I'm not sure why I threw dictionary into the question, but your suggestion is exactly what I was looking for. Thanks! – Just_Another_College_Student Dec 23 '20 at 21:02
  • no problem, make sure you understand the difference between list, dictionary, tuple, DataFrame, Series, etc. Those are fundamental data structures to tie down for programming / pandas. – David Erickson Dec 23 '20 at 21:11

0 Answers0