question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: can't insert scalar value into empty dataframe

See original GitHub issue

Pandas version checks

  • I have checked that this issue has not already been reported.

  • 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

INSTALLED VERSIONS

commit : 4bfe3d07b4858144c219b9346329027024102ab6 python : 3.8.12.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19044 machine : AMD64 processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : English_United States.1252

pandas : 1.4.2 numpy : 1.22.2 pytz : 2021.3 dateutil : 2.8.2 pip : 22.0.3 setuptools : 59.8.0 Cython : None pytest : 7.0.0 hypothesis : None sphinx : 4.4.0 blosc : None feather : 0.4.1 xlsxwriter : None lxml.etree : 4.7.1 html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.3 IPython : 8.0.1 pandas_datareader: None bs4 : None bottleneck : None brotli : fastparquet : None fsspec : 2022.01.0 gcsfs : None markupsafe : 2.0.1 matplotlib : 3.2.2 numba : None numexpr : 2.7.3 odfpy : None openpyxl : 3.0.9 pandas_gbq : 0.17.0 pyarrow : 6.0.1 pyreadstat : None pyxlsb : None s3fs : 2022.01.0 scipy : 1.8.0 snappy : None sqlalchemy : 1.4.31 tables : 3.7.0 tabulate : None xarray : 0.21.1 xlrd : 2.0.1 xlwt : None zstandard : None

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
phoflcommented, Jul 7, 2022

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

0reactions
phoflcommented, Dec 9, 2022

Because a column gets added, just no values in it. Closing now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: Appending Value to a dataframe - Stack Overflow
When you make DataFrame with no initial data, the DataFrame has no data and no columns. So you can't append any data I...
Read more >
Assigning a scalar value to an empty DataFrame doesn't ...
I'm new to pandas and have a very basic question, please! On Python v3.6 through spyder: x= pd.DataFrame(columns = ['1','2']) print(x) x['1'] =...
Read more >
What's new in 1.3.0 (July 2, 2021) - Pandas
When setting an entire column using loc or iloc , pandas will try to insert the values into the existing data rather than...
Read more >
How to Fix Empty DataFrame when Merging Two ... - YouTube
I've spent the last couple of days trying to merge two # pandas # dataframes using the same inner merge I've done in...
Read more >
How to Fix: You are trying to merge on object and int64 columns
The easiest way to fix this error is to simply convert the year variable in the second DataFrame to an integer and then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found