-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
assigning column values to empty dataframe with loc #10017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
By setting the index to a 0-length array, you are actually setting the index. This is de-facto the same thing as
This is simply not allowed setting as you don't have an index length; you can do it in the constructor directly if you really want.
These semantics are not usually what you would do anyhow; use eg.
|
How do I add a column to a possibly empty, already existing dataframe? |
|
I thought that df['foo'] = 1 was deprecated. Because in some conditions which I'm not able to reproduce in a test, I got this warning: "A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead" |
@paolini certainly not. You are getting the warning because you are making changes to something else that is a view. You should check your code. See the documentation on that section. If it is still showing an error, then post your code. |
Ok, thanks for your support! |
Here Shouldn't the df have value 1 in the column foo. |
My code is displaying correct output till this:
but not getting my output when running this:
The code above is not displaying the dataset, rather it is displaying empty dataframe but dataframe is not empty. Please help me |
I want to add N/A value in empty columns, please help |
I'm trying to add a column to an existing dataframe. The dataframe can be empty (0 rows) but I want the column to be added anyway.
The text was updated successfully, but these errors were encountered: