【发布时间】:2026-01-26 07:45:01
【问题描述】:
我遇到问题similar to this user:在df.col. 上调用自动完成时,即使在评估仅包含df.col 的单元格之后,我也没有自动完成。例如,我希望看到df.col.str.matc 自动完成到df.col.str.match。我能做些什么来解决这个问题?
以如下数据框为例:
import pandas as pd
data = [['Alex in FL','ten'],['Bob in FLORIDA','five'],['Will in GA','three']]
df = pd.DataFrame(data,columns=['Name','Age'])
#Dataframe:
Name Age
0 Alex in FL ten
1 Bob in FLORIDA five
2 Will in GA three
#Command that should autocomplete (but does not):
df.Name.str.matc [+TAB]
我不想尝试hinterland,因为我只想在按 Tab 时自动完成。
提前非常感谢!
【问题讨论】:
-
df.columns.str.match是您正在寻找的东西。df.col. +tab不会给出任何东西,因为没有像df.col.这样的东西(col 不是数据框的属性)。 -
@vb_rises 澄清一下,
col是df中的列之一,因此df.col是一个系列。但无论如何,df.columns.str.matc + tab仍然不会自动完成。问题依旧 -
如果
col包含'abc'、'def' 之类的字符串值,或者换句话说,它的类型是对象,那么df.col.str.mat + tab将起作用。但如果col具有整数或浮点值(类型为int 或float),则df.col.str.mat + tab不会自动完成。您可以将其转换为x = df.col.astype('str'),然后尝试x.str.mat + tab,它应该可以工作。 -
@vb_rises 谢谢。我将编辑我的问题以澄清这些要点,但我的数据框属于您的第一个示例,但它在任何情况下都不起作用。
-
您更新的示例非常适合我。我的熊猫版本是
0.19.2。检查你的版本。我希望您在初始化 df 后在新 CELL 中运行df.Name.st.mat+ TAB。
标签: python pandas jupyter-notebook jupyter