简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM