Convert Yaml to excel in Python

0 votes

I'm not sure how to effectively parse a yaml file such that it becomes an excel file.

I tried something similar, but I believe that I could recreate the model's original Excel appearance much more quickly:

for i,planche in enumerate (my_data["Culture par planche"]):
#print(planche)
for _planche in planche:
    print(planche[_planche][0]["surface"][0]["2"][0])

My yaml file content :

- Culture par planche :
- Planche A:
    - surface:
        - "2":
            - 198
    - Zones:
        - "1":
            - Rangs:
                - "1":
                    - surface:
                        - "2":
                            - 33
                    - plantes:
                        - Aubergine:
                            - nombre: 21
                            - surface totale nécessaire: 15
                            - poids total: 42
                            - Plantation:
                                - 5
                                - 6
                                - 7
                            - Récolte:
                                - 7
                                - 8
                                - 9
                                - 10
                                - 1
                        - Betteraves:
                            - nombre: 660
                            - surface totale nécessaire: 15
                            - poids total: 42
                            - Plantation:
                                - 1
                                - 2
                                - 3
                                - 4
                            - Récolte:
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                        - Epinards:
                            - nombre: 33
                            - surface totale nécessaire :3
                            - poids total :5
                            - Plantation:
                                - 10
                            - Récolte:
                                - 1
                                - 10
                                - 11
                                - 12
                        - Pois:
                            - nombre: 13
                            - surface totale nécessaire: 3
                            - poids total: 4.5
                            - Plantation:
                                - 2
                                - 3
                                - 4
                                - 5
                                - 6
                                - 7
                            - Récolte:
                                - 3
                                - 4
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                        - Blettes-poirées:
                            - nombre: 60
                            - surface totale nécessaire: 15
                            - poids total: 120
                            - Plantation:
                                - 1
                                - 2
                                - 3
                                - 4
                            - Récolte:
                                - 1
                                - 2
                                - 3
                                - 4
                                - 5
                        - Navet:
                            - nombre: 900
                            - surface totale nécessaire: 15
                            - poids total :30
                            - Plantation:
                                - 12
                            - Récolte:
                                - 1
                                - 2
                                - 3
                                - 4
                        - Fèves:
                            - nombre: 300
                            - surface totale nécessaire: 15
                            - poids total: 11.25
                            - Plantation:
                                - 10
                                - 11
                                - 12
                            - Récolte:
                                - 4
                                - 5
                - "2":
                    - surface:
                        - "2":
                            - 33
                    - plantes:
                        - Fraise:
                            - nombre: 132
                            - surface totale nécessaire: 33
                            - poids total: 105
                            - Plantation:
                                - 1
                                - 2
                                - 3
                                - 4
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                                - 11
                                - 12
                            - Récolte:
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                        - Ail:
                            - nombre: 200
                            - surface totale nécessaire: 10
                            - poids total: 20
                            - Plantation:
                                - 10
                                - 11
                                - 12
                            - Récolte:
                                - 5
                                - 6
                - "3":
                    - surface:
                        - "2":
                            - 33
                    - plantes:
                        - Piments:
                            - nombre: 40
                            - surface totale nécessaire: 10
                            - poids total: 6
                            - Plantation:
                                - 3
                                - 4
                            - Récolte:
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                        - Poivrons:
                            - nombre: 30
                            - surface totale nécessaire: 10
                            - poids total: 50
                            - Plantation:
                                - 3
                                - 4
                            - Récolte:
                                - 6
                                - 10
                        - Haricots fil et rame:
                            - nombre: 25
                            - surface totale nécessaire: 10
                            - poids total: 17
                            - Plantation:
                                - 4
                                - 5
                                - 6
                            - Récolte:
                                - 6
                                - 9
                        - Mesclun:
                            - nombre: 75
                            - surface totale nécessaire: 3
                            - poids total: 3
                            - Plantation:
                                - 3
                                - 4
                                - 5
                                - 6
                                - 7
                            - Récolte:
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                        - Navet:
                            - nombre: 1200
                            - surface totale nécessaire: 20
                            - poids total: 40
                            - Plantation:
                                - 11
                                - 12
                            - Récolte:
                                - 1
                                - 2
                                - 3
                                - 4
                                - 5
                                - 11
                                - 12
                        - Radis:
                            - nombre: 7785
                            - surface totale nécessaire: 13
                            - poids total: 39
                            - Plantation:
                                - 1
                                - 2
                                - 11
                                - 12
                            - Récolte:
                                - 1
                                - 2
                                - 3
                                - 4
                                - 5
                                - 11
                                - 12
                - "4":
                    - surface:
                        - "2":
                            - 33
                    - plantes:
                        - Tomates:
                            - nombre: 100
                            - surface totale nécessaire: 20
                            - poids total: 220
                            - Plantation:
                                - 3
                                - 4
                                - 5
                            - Récolte:
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                                - 11
                        - Carottes:
                            - nombre: 910
                            - surface totale nécessaire: 13
                            - poids total: 39
                            - Plantation:
                                - 2
                                - 3
                                - 4
                                - 5
                                - 6
                                - 7
                            - Récolte:
                                - 4
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                                - 11
                                - 12
                        - Oignons:
                            - nombre: 440
                            - surface totale nécessaire: 20
                            - poids total: 60
                            - Plantation:
                                - 1
                                - 2
                                - 11
                                - 12
                            - Récolte:
                                - 1
                                - 2
                                - 3
                                - 4
                                - 5
                - "5":
                    - surface:
                        - "2":
                            - 33
                    - plantes:
                        - Tomates cerises:
                            - nombre: 100
                            - surface totale nécessaire: 20
                            - poids total: 240
                            - Plantation:
                                - 3
                                - 4
                                - 5
                            - Récolte:
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                        - Concombre:
                            - nombre: 13
                            - plans: 13
                            - INFO - 1 plante == 1 plan produit N concombres
                            - VOIR - rendement d'un plan de concombre
                            - poids total: 195
                            - Plantation:
                                - 3
                                - 4
                                - 5
                            - Récolte:
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                        - Roquette:
                            - nombre: 390
                            - surface totale nécessaire: 13
                            - poids total: 13
                            - Plantation:
                                - 8
                                - 9
                                - 10
                            - Récolte:
                                - 3
                                - 4
                                - 10
                                - 11
                        - Pois: null
                        - nombre: 85
                        - surface totale nécessaire: 20
                        - poids total: 30
                        - Plantation:
                            - 9
                            - 10
                        - Récolte:
                            - 10
                            - 11
                            - 12
                - "6":
                    - surface:
                        - "2":
                            - 33
                    - plantes:
                        - Fraise:
                            - nombre: 132
                            - surface totale nécessaire: 33
                            - poids total: 105
                            - Plantation:
                                - 1
                                - 2
                                - 3
                                - 4
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                                - 11
                                - 12
                            - Récolte:
                                - 5
                                - 6
                                - 7
                                - 8
                                - 9
                                - 10
                        - Ail:
                            - nombre: 200
                            - surface totale nécessaire: 10
                            - poids total: 20
                            - Plantation:
                                - 10
                                - 11
                                - 12
                            - Récolte:
                                - 5
                                - 6

It's kinda huge but so you have the entire structure of a "planche", the entire yaml file contains 4 "planches"

this is how the excel model looks like basically :

enter image description here

Anybody with information on how to quickly fill out data is welcome! PS: The integers in "Plantation" and "Recolte" denote the months of the year.

Mar 27, 2023 in Others by Kithuzzz
• 38,010 points
692 views

1 answer to this question.

0 votes

You can try this:

First, install dependencies:

pip install xmltodict
pip install pyyaml

answered Mar 27, 2023 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer

How to convert data from txt files to Excel files using python

Hi , there are few steps to ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
13,293 views
0 votes
0 answers

Convert Rows to Columns with values in Excel using custom format

1 I having a Excel sheet with 1 ...READ MORE

Feb 17, 2022 in Others by Edureka
• 13,670 points
698 views
0 votes
1 answer

Convert image (jpg) to base64 in Excel VBA?

Heres a function. Can't remember where I ...READ MORE

answered Sep 27, 2022 in Others by narikkadan
• 63,420 points
2,052 views
0 votes
1 answer

How to convert PDF to Excel in C#?

Solutions a) Cometdocs makes a free online conversion from PDF ...READ MORE

answered Oct 1, 2022 in Others by narikkadan
• 63,420 points
640 views
0 votes
1 answer

Converting all tabs of excel sheet to PDF

Using VBA, try it like this, for ...READ MORE

answered Sep 26, 2022 in Others by narikkadan
• 63,420 points
1,289 views
0 votes
1 answer

How search data in excel with openpyxl?

The method iter_rows in the library has changed, refer ...READ MORE

answered Oct 2, 2022 in Others by narikkadan
• 63,420 points
5,577 views
0 votes
1 answer

How to insert info into online excel spreadsheet with python selenium

I recently discovered one of my options, ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,420 points
895 views
0 votes
1 answer

Python Excel Writer (xlswriter) Insert Image from URL

Use this: url = "..../picture.jpg" data = urllib.request.urlopen(url).read() file = ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 63,420 points
1,424 views
0 votes
1 answer

Convert table in a jpg image to excel using python

I believe you must execute OCR (optical ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 63,420 points
1,809 views
0 votes
1 answer

Print chosen worksheets in excel files to pdf in python

In the simplest form: import win32com.client o = win32com.client.Dispatch("Excel.Application") o.Visible ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,420 points
2,670 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP