Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame({})
df.insert(0, "test", 6)
# >>> df
# Empty DataFrame
# Columns: [test]
# Index: []
Issue Description
Scalar value not inserted into dataframe.
Expected Behavior
Maybe result should be something like this?
>>> df
test
0 6
Installed Versions
Comment From: phofl
I think not inserting the value makes sense here. A scalar is set into the whole column, since the column is empty, nothing happens.
df = pd.DataFrame({})
df["x"] = 0
This behaves the same, which also makes sense imo
Comment From: anmyachev
The strange thing here is that the column is being added, but it remains empty.
Comment From: phofl
Imo this is as expected. The index determines how many rows we have, since it is empty we don't get any rows. Same with a regular setitem
Comment From: phofl
Labelling as usage question and would close if no objections
Comment From: anmyachev
Onw more question here: if in the end the scalar value was not added, then why add a column to an empty dataframe?
Comment From: phofl
Because a column gets added, just no values in it. Closing now