I need to create an Excel spreadsheet dynamically that looks something like this:
_______________________________________________________
| Name | Start Date | Title | Companies | Sub-companies |
|-------------------------------------------------------|
| Jim | 01/01/2010 | CTO | Google | YouTube |
|-------------------------------------------------------|
| | | | | FitBit |
|-------------------------------------------------------|
| | | | Apple | NextVR |
|-------------------------------------------------------|
| | | | | Beats |
|-------------------------------------------------------|
| Tom | 12/12/2020 | CEO | Amazon | Audible |
|-------------------------------------------------------|
| | | | | Zappos |
|-------------------------------------------------------|
| | | | Samsung | Biologics |
|-------------------------------------------------------|
| | | | | Cheil |
|-------------------------------------------------------|
This is my code so far:
import pandas as pd
df = pd.DataFrame({
"Name": ["Jim", "Tom"],
"Start Date": ["01/01/2010", "12/12/2020"],
"Companies": ["Google", "Apple", "Amazon", "Samsung"],
"Sub-companies": [
"YouTube", "FitBit", "NextVR", "Beats",
"Audible", "Zappos", "Biologics", "Cheil"
]
})
print(df)
df.to_excel("output.xlsx", sheet_name="Webtoons Comic Data")
This doesn't work because "all arrays must be same length" How can I go about doing this? My current plan is to make it line-by-line by adding empty spaces to each column array. Is there a better way to do it? I don't need help populating the arrays, just structuring the DF itself. Thanks for your help.