Series operations
There exist a vast number of operators in Python for manipulating objects. For instance, when the plus operator is placed between two integers, Python will add them together:
>>> 5 + 9 # plus operator example. Adds 5 and 9
14
Series and DataFrames support many of the Python operators. Typically, a new Series or DataFrame is returned when using an operator.
In this recipe, a variety of operators will be applied to different Series objects to produce a new Series with completely different values.
How to do it…
- Select the
imdb_score
column as a Series:>>> movies = pd.read_csv("data/movie.csv") >>> imdb_score = movies["imdb_score"] >>> imdb_score 0 7.9 1 7.1 2 6.8 3 8.5 4 7.1 ... 4911 7.7 4912 7.5 4913 6.3 4914 6.3 4915 6.6 Name: imdb_score, Length: 4916, dtype: float64
- Use the plus operator...