Pandas#
Create a Pandas series called
x
with all positive integers from 0 to 99.
Create another Pandas series derived from
x
which contains the values of \(x^2\). Call this Seriesx_squared
.
Create a Pandas data frame containing
x
andx_squared
as columns.
Add a column with the cosine of
x_squared
in degrees and call itcos_x_squared
. (Hint 1: Use themath
module for getting a value forpi
and for thecos
function. Hint 2: It is not possible to callmath.cos
directly on a Pandas series, but we can use.apply(math.cos)
on a series.)
Select every second line from the dataframe starting on line 23 and print the selection.
Choose
x
as the index of the dataframe. Then print the portion of the dataframe which represents values ofx
between 11.3 and 47.5.
Write the data frame to disk (into a CSV file). Then, load the CSV file into a new dataframe.
Visualize the columns
x_squared
andcos_x_squared
against the indexx
.
Change the index to
x_squared
and visualize the clumncos_x_squared
against the new index.