2

Is there any way to make VS Code suggest all dataframe column labels?

screenshot showing suggestions list

From the above sample dataframe, I expect all the column labels (Country, Product, Price, Qty) is going to popup. But none show up after I select 'Country'.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • I just edited the question and I realized you weren't using any of the exact terminology before. Hopefully this gives you some terms you can try researching :) I'd like to know too. "Intellisense" is another one. – wjandrea Apr 15 '23 at 01:56
  • Oh, I just noticed the Jupyter extension does suggest column names, but you have to start typing them first. Is that what you're talking about? – wjandrea Apr 15 '23 at 02:10
  • Possibly related: https://stackoverflow.com/q/43890844/11107541, https://stackoverflow.com/q/69728330/11107541 – starball Apr 15 '23 at 02:14
  • Related, maybe a duplicate: [Is there a way to get autocompletion for pandas dataframe columns in VSCode editor or interactive mode?](/q/69628815/4518341) – wjandrea Apr 15 '23 at 02:15
  • @wjandrea I'd say this question is different because it's parsing a dataframe from a file _at runtime_ (I'm currently writing up an answer) – starball Apr 15 '23 at 02:24
  • did you get suggestions for `'Country'`? Or did you type that all in manually? – starball Apr 15 '23 at 02:37
  • 1
    I do get 'Country' (and other labels as well) as suggestion. But the suggestion only works one time when none of the label is selected. After I selected one label, the suggestion (or popup) does not work anymore. – user13617491 Apr 15 '23 at 03:10
  • then your question is not correct. You get completion on the first tuple element of the data frame array index but on following tuple elements. maybe the type definition for `DataFrame[]` can be modified so VSC Jupyter suggests next column names – rioV8 Apr 15 '23 at 08:24
  • @user in your answer you suggest to write a VSC extension to do this, but are we able to write an extension that interacts with the Jupyter Webview (??), and that is able to do runtime Python introspection – rioV8 Apr 15 '23 at 08:29
  • @rioV8 I'm actually not sure. Good thing I deleted that answer I suppose. – starball Apr 15 '23 at 14:37
  • @user13617491 If you start typing the other column names, do they appear in the suggestions? – wjandrea Apr 15 '23 at 18:26
  • @user The question I linked doesn't say anything about runtime... I mean, the answer does define a df at runtime, but it doesn't actually affect anything. Maybe you're confused with `text` suggestions? (`editor.suggest.showWords`) Those would have a little "abc" symbol instead of a wrench (though, I get a cube on mine, but then I'm using Jedi with Codium). – wjandrea Apr 15 '23 at 18:26
  • Oh wait a minute, does the dataframe have a MultiIndex? Cause if not, then to select multiple columns, you need to put a list, i.e. double up the brackets: `data[['Country','']]`. It'd help to provide a [mre]. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). – wjandrea Apr 15 '23 at 18:35
  • Er, actually, I just tried doubling up the brackets myself and no column suggestions came up no matter what I tried... But I'm using Jedi (i.e. not Pylance) on Codium so YMMV. To be clear, if I put single brackets and start typing column names, they do get suggested. – wjandrea Apr 15 '23 at 18:53

0 Answers0