1

PTPA

Not sure if this is allowed if not please delete it

I am a novice in python and was trying to create a script that will parse xlsx data to python and use it to create a yaml file that will be used for ansible purpose.

Im stuck with the following type of excel column:

| Column A |

|:—————:|

| CA.1 | CA.2 |

|:—————:|:—————:|

| VA.1 | VA.2 |

I wanted to put it in a dictionary like for example:

Column A: { ColumnA.1 : ValueA.1 , ColumnA.2 : Value A.2}

So that I could create a yaml file like:

Column A:

  • ColumnA.1 : Value A.1
  • ColumnA.2 : Value A.2

I would appreciate your input on this one. Thanks

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions – Youba Jan 06 '21 at 08:21

1 Answers1

1

At a high level I would:

  • use pandas to ingest the Excel file pd.read_excel - docs
  • list comprehension to create the dictionary SO post
  • and yaml.dump to generate your file SO post

edit:

be sure to look at how yaml.dump executes, this will inform how you turn the pandas dataframe into a dictionary -- though you might be able to use df.to_dict(), depending on how your Excel file is structured (to_dict docs)

Dharman
  • 30,962
  • 25
  • 85
  • 135
willwrighteng
  • 1,411
  • 11
  • 25