NumEconCopenhagen / lectures-2019

Slides and code used in the lectures
MIT License
13 stars 23 forks source link

Selecting specefic variables in a dataframe #12

Open Gandalfearless opened 5 years ago

Gandalfearless commented 5 years ago

Hello!

Is it possible to lock a column to multiple specific variables in your dataframe? We want to select the variables called "Y" and "Y_L". We can't find a simple way to select these variables. The way we do it now works, but it is a troublesome way to do it. We are right now dropping every variable that we don't need. It works when you don't have that many variables, but it is not that effective when you have a lot.

It would be nice if we could write something like:
"samle1234=samle1234[samle1234.variable==["Y" & "Y_L"]] But unfortunately this doesn't work.

The code: image output: image

We hope that you can help Best regards

JeppeDruedahl commented 5 years ago

Try something like df = df.loc[:,['variableA','variableB']]. `