SSCC - Social Science Computing Cooperative Supporting Statistical Analysis for Research

2.1 Data frames

  1. Create a data frame with three observations of two variables. Name the variables x1 and x2. Make up numbers for the values of the observed variables.

    Set RStudio to python mode

    library(reticulate)
    repl_python()
    import pandas as pd
    my_data = (
        pd.DataFrame(data={
            'x1': [1, 2, 3],
            'x2': ["c", "b", "a"]}))
  2. Using any of the functions/methods from the discourse, display the number of observations and variables of the data frame.

    print(my_data.shape)
    (3, 2)

    Or

    print(my_data.head())
       x1 x2
    0   1  c
    1   2  b
    2   3  a