Adding new column to existing DataFrame in Python pandas

Edit 2017 As indicated in the comments and by @Alexander, currently the best method to add the values of a Series as a new column of a DataFrame could be using assign: Edit 2015Some reported getting the SettingWithCopyWarning with this code.However, the code still runs perfectly with the current pandas version 0.16.1. The SettingWithCopyWarning aims to inform of a possibly … Read more

Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

The or and and python statements require truth-values. For pandas these are considered ambiguous so you should use “bitwise” | (or) or & (and) operations: These are overloaded for these kind of datastructures to yield the element-wise or (or and). Just to add some more explanation to this statement: The exception is thrown when you want to get the bool of a pandas.Series: What you hit was a place where the operator implicitly converted … Read more