I had a look on google and on here to try find the answer but couldn't seem to word it correctly to get help with this exact issue.
I want to create a Dataframe which has a column called 'Department' with values from a list and then for each value in that column I want the same datetime range.
The list is:
departments = ['Sales', 'Specialist', 'Purchase', 'HR']
and the daterange is (the df being a different dataframe I have with the original date range.):
pd.date_range(start=df.InvoiceDate.min(), end=df.InvoiceDate.max(), freq='1D')
So, I tried this but it gave me an error because of the shape, which I understand just not sure how to solve it.
df2 = pd.DataFrame(department,(pd.date_range(start=df.InvoiceDate.min(), end=df.InvoiceDate.max(), freq='1D')), columns=['Department',"InvoiceDate"])
The desired outcome is something like this:
Department InvoiceDate
0 Sales 2019-03-25
1 Sales 2019-03-26
2 Sales 2019-03-27
...
5 Specialist 2019-03-25
6 Specialist 2019-03-26
7 Specialist 2019-03-27
...
8 Purchase 2019-03-25
9 Purchase 2019-03-26
10 Purchase 2019-03-27
...
11 HR 2019-03-25
12 HR 2019-03-26
13 HR 2019-03-27
Thank you
EDIT: Error Code
>>> df2 = pd.DataFrame(workstream,(pd.date_range(start=df.InvoiceDate.min(), end=df.InvoiceDate.max(), freq='1D')), columns=['WorkStream',"InvoiceDate"])
Traceback (most recent call last):
File "C:\Python38-32\lib\site-packages\pandas\core\internals\managers.py", line 1678, in create_block_manager_from_blocks
make_block(values=blocks[0], placement=slice(0, len(axes[0])))
File "C:\Python38-32\lib\site-packages\pandas\core\internals\blocks.py", line 3284, in make_block
return klass(values, ndim=ndim, placement=placement)
File "C:\Python38-32\lib\site-packages\pandas\core\internals\blocks.py", line 2792, in __init__
super().__init__(values, ndim=ndim, placement=placement)
File "C:\Python38-32\lib\site-packages\pandas\core\internals\blocks.py", line 126, in __init__
raise ValueError(
ValueError: Wrong number of items passed 1, placement implies 2
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python38-32\lib\site-packages\pandas\core\frame.py", line 464, in __init__
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
File "C:\Python38-32\lib\site-packages\pandas\core\internals\construction.py", line 213, in init_ndarray
return create_block_manager_from_blocks(block_values, [columns, index])
File "C:\Python38-32\lib\site-packages\pandas\core\internals\managers.py", line 1688, in create_block_manager_from_blocks
construction_error(tot_items, blocks[0].shape[1:], axes, e)
File "C:\Python38-32\lib\site-packages\pandas\core\internals\managers.py", line 1718, in construction_error
raise ValueError(
ValueError: Shape of passed values is (8, 1), indices imply (533, 2)