Tri Nguyen
Tri Nguyen

Reputation: 65

Does Python have any equivalent to R's $ sign?

I am having trouble when migrating to Python from R. When I worked with data frame in R, using the dollar sign will let know all the name of the column and easily choose the one that i need from a suggestion list even though I don't remember exactly the column's name. Is there any way I can do that in Python?

Update:

Thank you all for the quick respondes. I have looked around and figured out that using df. to bring up the auto complete box works only in the console, not in the editor. However, I have no idea whether it is a bug, or JetBrains just hasn't implemented the feature from R yet.

Upvotes: 1

Views: 840

Answers (2)

Kota Mori
Kota Mori

Reputation: 6750

You can use a dot for pandas data frame as though the dollar sign in the R's data frame. Since pandas data frame has a lot of other attributes than the column names, you may need to type the few first letters to narrow the suggestion list convenient enough.

import pandas as pd
x = pd.DataFrame({"X1": [1,2,3], "X2": [4,5,6]})
x.

Then type TAB key would trigger the auto completion feature.

Upvotes: 0

chthonicdaemon
chthonicdaemon

Reputation: 19830

There are two parts to your question: there is a language part about what the equivalent syntax/usage is and a platform part about how things are exposed to the user.

The language part is that indexing using df["colname"] in on a Pandas Dataframe is the equivalent of df$colname in R. Depending on your column name, you might also be able to use df.colname although I discourage this usage.

If you would like to have completion of this, Jupyter Lab supports tab completion on dataframes, where you would type df["<tab> and see a list of possible column completions.

Upvotes: 3

Related Questions