Hi All,
I have an excel file with two columns: table and number.
All I want to do is use Python to load an excel file, loop through each row and write the row to a new file as many times as the respective number.
For example the excel file will have (in reality is's much bigger of course):
apples, 1
oranges, 3
grapefruit, 1
banana, 2
The new file will look like this:
apples (1)
oranges (1)
oranges (2)
oranges (3)
grapefruit (1)
bananas (1)
bananas (2)
I've spent 3 hours solid trying to find a way to do this and not even got close to a solution. I've been able to use pandas to read in the data and print it but I can't get my head around how to do the above. I'm now confused to which plugin/tool I should even use.
Going to be honest - I'm teaching myself Python and I am a beginner. I'd usually say I learn really quick but this proving tough. While I appreciate it takes time to learn the basics I do need to get this work done (ideally not manually).
I've got no code of any value to add other printing the two columns from a panda data frame which I'm not sure is even the correct way to go.
Not looking for someone to do my work for me but I could really do with a kind pointer or two to get me going.
As note I'm running Python 3 on Windows 10 installed using Anaconda.
I'm writing my code in Notepad++ and executing in Jupyter QTConsole.
Many thanks
Richard
I have an excel file with two columns: table and number.
All I want to do is use Python to load an excel file, loop through each row and write the row to a new file as many times as the respective number.
For example the excel file will have (in reality is's much bigger of course):
apples, 1
oranges, 3
grapefruit, 1
banana, 2
The new file will look like this:
apples (1)
oranges (1)
oranges (2)
oranges (3)
grapefruit (1)
bananas (1)
bananas (2)
I've spent 3 hours solid trying to find a way to do this and not even got close to a solution. I've been able to use pandas to read in the data and print it but I can't get my head around how to do the above. I'm now confused to which plugin/tool I should even use.
Going to be honest - I'm teaching myself Python and I am a beginner. I'd usually say I learn really quick but this proving tough. While I appreciate it takes time to learn the basics I do need to get this work done (ideally not manually).
I've got no code of any value to add other printing the two columns from a panda data frame which I'm not sure is even the correct way to go.
Not looking for someone to do my work for me but I could really do with a kind pointer or two to get me going.
As note I'm running Python 3 on Windows 10 installed using Anaconda.
I'm writing my code in Notepad++ and executing in Jupyter QTConsole.
Many thanks
Richard