{"id":851,"date":"2025-09-04T09:04:07","date_gmt":"2025-09-04T09:04:07","guid":{"rendered":"http:\/\/www.lexique.org\/?page_id=851"},"modified":"2025-09-04T09:04:08","modified_gmt":"2025-09-04T09:04:08","slug":"how-to-query-lexique-with-python","status":"publish","type":"page","link":"http:\/\/www.lexique.org\/?page_id=851&lang=en","title":{"rendered":"How to query Lexique with Python"},"content":{"rendered":"\n<p>This example shows how to select four random sets of twenty nouns and verbs of low and high frequencies from Lexique382, using Python. (If you have not already, install Python: Go to <a href=\"https:\/\/www.anaconda.com\/distribution\/\">https:\/\/www.anaconda.com\/distribution\/<\/a>; select your OS (Windows, MacOS or Linux) and download the Python 3.7 installer.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\"\"\" Example of selecting items from the Lexique382 database \"\"\"\n\nimport pandas as pd\n\nlex = pandas.read_csv('http:\/\/www.lexique.org\/databases\/Lexique382\/Lexique382.tsv', sep='\\t')\n\n# alternatively, you can download the table locally:\n# lex = pd.read_csv(\"Lexique382.tsv\", sep='\\t')\n\nlex.head()\n\n# restricts the search to words with a length between 5 and 8 letters\nsubset = lex.loc[(lex.nblettres >= 5) &amp; (lex.nblettres &lt;= 8)]\n\n# separates nouns and verbs into two dataframes:\nnoms = subset.loc[subset.cgram == 'NOM']\nverbs = subset.loc[subset.cgram == 'VER']\n\n# splits based on lexical frequency\nnoms_hi = noms.loc[noms.freqlivres > 50.0]\nnoms_low = noms.loc[(noms.freqlivres &lt; 10.0) &amp; (noms.freqlivres > 1.0)]\n\nverbs_hi = verbs.loc[verbs.freqlivres > 50.0]\nverbs_low = verbs.loc[(verbs.freqlivres &lt; 10.0) &amp; (verbs.freqlivres > 1.0)]\n\n# chooses random items from each of the 4 subsets:\nN = 20\nnoms_hi.sample(N).ortho.to_csv('nomhi.txt', index=False)\nnoms_low.sample(N).ortho.to_csv('nomlo.txt', index=False)\nverbs_hi.sample(N).ortho.to_csv('verhi.txt', index=False)\nverbs_hi.sample(N).ortho.to_csv('verlo.txt', index=False)\n<\/code><\/pre>\n\n","protected":false},"excerpt":{"rendered":"<p>This example shows how to select four random sets of twenty nouns and verbs of low and high frequencies from Lexique382, using Python. (If you have not already, install Python: Go to https:\/\/www.anaconda.com\/distribution\/; select your OS (Windows, MacOS or Linux) and download the Python 3.7 installer.)<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":841,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-851","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lexique.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=851"}],"version-history":[{"count":1,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/851\/revisions"}],"predecessor-version":[{"id":852,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/851\/revisions\/852"}],"up":[{"embeddable":true,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/841"}],"wp:attachment":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}