Pandas

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 Series x_squared.

  • Create a Pandas data frame containing x and x_squared as columns.

  • Add a column with the cosine of x_squared in degrees and call it cos_x_squared. (Hint 1: Use the math module for getting a value for pi and for the cos function. Hint 2: It is not possible to call math.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 of x 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 and cos_x_squared against the index x.

  • Change the index to x_squared and visualize the clumn cos_x_squared against the new index.