-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Assignments: numerics, strings and .loc #6171
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
This is not valid python code (what you pasted)
|
Presumably missing square brackets. |
Yea I retyped it manually, a typo. |
can you fix the examples pls |
Fixed typos, should work now; sry had to type it manually. Huh, more weird stuff, check this out: >>> df = pd.DataFrame(columns=['x', 'y'])
>>> df.x = [1, 2] # no error?
>>> df.y # expect [nan, nan]?
ValueError: Wrong number of items passed 2, indices imply 0 Btw: this is v0.13.0, not the head rev; not sure if it has been addressed or not already but I skimmed through recent changes/issues and haven't found anything related. |
assigning to columns via setattr is currently an open issue (should this actually error), hard to say, see here: #5904 |
@jreback Still crashes with |
@aldanor what are you refurring to: |
@jreback Maybe I got it wrong; did you mean |
@aldanor pls roll the |
|
@aldanor FYI, I fixed the assignments to an empty frame; if you are finding bugs, great! but I would not use this in practice as you will almost always get object dtype so not that useful |
Yea I was just using the code above for cheap and dirty unit tests and was surprised to see it blows up (in many different ways). What do you mean by "always get the object dtype" though? Thanks for the quick PR; will move the |
Opened #6173 for |
I am talking about
|
Hmm... >>> df = pd.DataFrame(columns=['x', 'y'])
>>> df.dtypes
x NaN
y NaN
dtype: float64
>>> (df.x.dtype, df.y.dtype)
(dtype('O'), dtype('O'))
>>> df['x'] = [1, 2]
>>> df.dtypes
x int64
y object So x gets promoted to int64, y stays an object, looks ok? Why is the dtype of the empty dataframe is reported as float64 btw when both columns are object-type? |
that's right...was thinking of something else. an empty (index wise) frame by definition will have object dtypes. as I said, you should normally not do this, you can get into all sorts of werid things. a data frame does not have a dtype at all (its a series property) I am not sure what you are printing out
|
Yea, I know data frame has no dtype of its own, it's more of a cosmetic thing in this case; weird though -- at least on v0.13.0 / numpy 1.8.0 -- I get: pd.DataFrame(columns=['x', 'y']).dtypes
x NaN
y NaN
dtype: float64 This behaves different on master? |
yes, IIRC I did fix this after 0.13 can you test out things on master if you suspect bugs? I really do appreciated the reports! sometimes don't remember fixing things (and issues get confused); though we are pretty organized on that. |
and you are seeing the |
Why would assigning an entire column to an array of values work differently with numbers vs strings?
Assigning numeric values:
Assigning string values:
Btw according to latest docs
.loc
can append, but can it append more than one value at once?Setting multiple via
.loc
:Setting single via
.loc
: (this works ofc)The text was updated successfully, but these errors were encountered: