CausalAIBook / MetricsMLNotebooks

Notebooks for Applied Causal Inference Powered by ML and AI
MIT License
74 stars 37 forks source link

PM1_prediction.ipynb Jupyter Book Cannot Load .RData #1

Open Eli-m93 opened 2 years ago

Eli-m93 commented 2 years ago

The current code links to github's wage data which is only an RData dataset, then the code reads:

Data Analysis
Set the following file_directory to a place where you downloaded https://github.com/CausalAIBook/MetricsMLNotebooks/blob/main/PM1/wage2015_subsample_inference.rdata

file_dir = None
df = pd.read_csv(file_dir)

I found two solutions:

  1. Import RData to Pandas ready package (taken from my collab code):
    !pip install pyreadr
    import pyreadr
    import numpy as np
    import pandas as pd
    temp = pyreadr.read_r('/content/wage2015_subsample_inference.Rdata')
    df = temp['data']
  2. Upload a CSV
Togeka commented 2 years ago

having similar problems, where is the CSV located?

Eli-m93 commented 2 years ago

having similar problems, where is the CSV located?

Hi Togeka, you can copy and paste this code into google collab to read RData into your jupyter notebook:

!pip install pyreadr
import pyreadr
import numpy as np
import pandas as pd
temp = pyreadr.read_r('/content/wage2015_subsample_inference.Rdata')
df = temp['data']

On google collab you need to literally click the folder icon on the right hand side, and manually upload the RData file onto the collab website to use it.

KendrickQ commented 2 years ago

Or you could transfer the rdata to csv file manually in your computer. This is the command you need to use in your local R Studio.

data = load("~/Downloads/wage2015_subsample_inference.rdata")
write.csv(data, file="~/Downloads/data.csv")

I doubt that these python notebooks haven't been checked.