[英]Does Python have any equivalent to R's $ sign?
I am having trouble when migrating to Python from R.从 R 迁移到 Python 时遇到问题。 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 .
当我在 R 中使用数据框时,使用美元符号将让知道列的所有名称并轻松地从建议列表中选择我需要的列,即使我不记得确切的列名。 Is there any way I can do that in Python?
有什么办法可以在 Python 中做到这一点?
Update:更新:
Thank you all for the quick respondes.谢谢大家的快速回复。 I have looked around and figured out that using
df.
我环顾四周,发现使用
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.
但是,我不知道这是否是一个错误,或者 JetBrains 还没有实现 R 的功能。
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.语言部分是在 Pandas Dataframe 中使用
df["colname"]
进行索引相当于 R 中的 df$colname。 Depending on your column name, you might also be able to use df.colname
although I discourage this usage.根据您的列名,您也可以使用
df.colname
尽管我不鼓励这种用法。
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.如果您想完成此操作,Jupyter Lab 支持数据帧上的制表符完成,您可以在其中键入
df["<tab>
并查看可能的列完成列表。
You can use a dot for pandas data frame as though the dollar sign in the R's data frame.您可以将点用于 pandas 数据帧,就像 R 数据帧中的美元符号一样。 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.
由于 pandas 数据框除了列名之外还有很多其他属性,您可能需要键入几个首字母以方便地缩小建议列表。
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.然后键入 TAB 键将触发自动完成功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.