{"id":900,"date":"2023-07-28T09:19:31","date_gmt":"2023-07-28T09:19:31","guid":{"rendered":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/"},"modified":"2023-07-28T09:19:31","modified_gmt":"2023-07-28T09:19:31","slug":"json-nel-dataframe-panda","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/","title":{"rendered":"Come convertire un file json in un pandas dataframe"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">A volte potresti voler convertire un file JSON in un DataFrame panda. Fortunatamente, questo \u00e8 facile da fare utilizzando la funzione <a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/reference\/api\/pandas.read_json.html\" target=\"_blank\" rel=\"noopener noreferrer\">read_json()<\/a> di panda, che utilizza la seguente sintassi:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>read_json(&#8216;percorso&#8217;, orientamento=&#8217;indice&#8217;)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Oro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>percorso:<\/strong> il percorso del tuo file JSON.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>orient:<\/strong> l&#8217;orientamento del file JSON. Il valore predefinito \u00e8 &#8220;indice&#8221;, ma \u00e8 possibile specificare invece &#8220;divisione&#8221;, &#8220;record&#8221;, &#8220;colonne&#8221; o &#8220;valori&#8221;.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare questa funzione per una variet\u00e0 di stringhe JSON diverse.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: conversione di un file JSON con un formato &#8220;Record&#8221;.<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere un file JSON chiamato <strong>my_file.json<\/strong> nel seguente formato:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong>[<\/strong><span style=\"color: #000000;\"><strong>\n   {\n      \"points\": 25,\n      \u201cassists\u201d: 5\n   },\n   {\n      \"points\": 12,\n      \u201cassists\u201d: 7\n   },\n   {\n      \"points\": 15,\n      \u201cassists\u201d: 7\n   },\n   {\n      \"points\": 19,\n      \u201cassists\u201d: 12\n   }\n]<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo caricare questo file JSON in un DataFrame panda semplicemente specificando il percorso con orient=&#8217; <strong>records<\/strong> &#8216; come segue:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong><span style=\"color: #000000;\"><span style=\"color: #008080;\">#load JSON file into pandas DataFrame<\/span>\ndf = pd. <span style=\"color: #3366ff;\">read_json<\/span> ('C:\/Users\/Zach\/Desktop\/json_file.json',<\/span> orient=' <span style=\"color: #008000;\">records<\/span> ')\n\n<span style=\"color: #008080;\">#view DataFrame\n<span style=\"color: #000000;\">df\n\n        assist points\n0 5 25\n1 7 12\n2 7 15\n3 12 19\n<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: conversione di un file JSON con un formato &#8220;Indice&#8221;.<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere un file JSON chiamato <strong>my_file.json<\/strong> nel seguente formato:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong>{\n   \"0\": {\n      \"points\": 25,\n      \u201cassists\u201d: 5\n   },\n   \"1\": {\n      \"points\": 12,\n      \u201cassists\u201d: 7\n   },\n   \"2\": {\n      \"points\": 15,\n      \u201cassists\u201d: 7\n   },\n   \"3\": {\n      \"points\": 19,\n      \u201cassists\u201d: 12\n   }\n}<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo caricare questo file JSON in un DataFrame panda semplicemente specificando il percorso con orient=&#8217; <strong>index<\/strong> &#8216; come segue:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong><span style=\"color: #000000;\"><span style=\"color: #008080;\">#load JSON file into pandas DataFrame<\/span>\ndf = pd. <span style=\"color: #3366ff;\">read_json<\/span> ('C:\/Users\/Zach\/Desktop\/json_file.json',<\/span> orient=' <span style=\"color: #008000;\">index<\/span> ')\n\n<span style=\"color: #008080;\">#view DataFrame\n<span style=\"color: #000000;\">df\n\n        assist points\n0 5 25\n1 7 12\n2 7 15\n3 12 19\n<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: conversione di un file JSON con un formato &#8220;Colonne&#8221;.<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere un file JSON chiamato <strong>my_file.json<\/strong> nel seguente formato:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong>{\n   \"dots\": {\n      \"0\": 25,\n      \"1\": 12,\n      \"2\": 15,\n      \"3\": 19\n   },\n   \"assists\": {\n      \"0\": 5,\n      \"1\": 7,\n      \"2\": 7,\n      \"3\": 12\n   }\n}<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo caricare questo file JSON in un DataFrame panda semplicemente specificando il percorso con orient=&#8217; <strong>columns<\/strong> &#8216; come segue:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong><span style=\"color: #000000;\"><span style=\"color: #008080;\">#load JSON file into pandas DataFrame<\/span>\ndf = pd. <span style=\"color: #3366ff;\">read_json<\/span> ('C:\/Users\/Zach\/Desktop\/json_file.json',<\/span> orient=' <span style=\"color: #008000;\">columns<\/span> ')\n\n<span style=\"color: #008080;\">#view DataFrame\n<span style=\"color: #000000;\">df\n\n        assist points\n0 5 25\n1 7 12\n2 7 15\n3 12 19<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 4: conversione di un file JSON con un formato &#8220;Values&#8221;.<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere un file JSON chiamato <strong>my_file.json<\/strong> nel seguente formato:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong>[\n   [\n      25,\n      5\n   ],\n   [\n      12,\n      7\n   ],\n   [\n      15,\n      7\n   ],\n   [\n      19,\n      12\n   ]\n]<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo caricare questo file JSON in un DataFrame panda semplicemente specificando il percorso con orient=&#8217; <strong>values<\/strong> &#8216; come segue:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 14px;\"> <strong><span style=\"color: #000000;\"><span style=\"color: #008080;\">#load JSON file into pandas DataFrame<\/span>\ndf = pd. <span style=\"color: #3366ff;\">read_json<\/span> ('C:\/Users\/Zach\/Desktop\/json_file.json',<\/span> orient=' <span style=\"color: #008000;\">values<\/span> ')\n\n<span style=\"color: #008080;\">#view DataFrame\n<span style=\"color: #000000;\">df\n\n        0<\/span> <span style=\"color: #000000;\">1\n0 25 5\n1 12 7\n2 15 7\n3 19 12\n3 12 19<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><em>Puoi trovare la documentazione completa della funzione read_json() <a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/reference\/api\/pandas.read_json.html\" target=\"_blank\" rel=\"noopener noreferrer\">qui<\/a> .<\/em><\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/i-panda-leggono-excel\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come leggere file Excel con Panda<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-leggono-csv\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come leggere file CSV con Pandas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A volte potresti voler convertire un file JSON in un DataFrame panda. Fortunatamente, questo \u00e8 facile da fare utilizzando la funzione read_json() di panda, che utilizza la seguente sintassi: read_json(&#8216;percorso&#8217;, orientamento=&#8217;indice&#8217;) Oro: percorso: il percorso del tuo file JSON. orient: l&#8217;orientamento del file JSON. Il valore predefinito \u00e8 &#8220;indice&#8221;, ma \u00e8 possibile specificare invece &#8220;divisione&#8221;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come convertire un file JSON in un Pandas DataFrame - Statorials<\/title>\n<meta name=\"description\" content=\"Una semplice spiegazione su come convertire un file JSON in un DataFrame panda.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come convertire un file JSON in un Pandas DataFrame - Statorials\" \/>\n<meta property=\"og:description\" content=\"Una semplice spiegazione su come convertire un file JSON in un DataFrame panda.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T09:19:31+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/\",\"url\":\"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/\",\"name\":\"Come convertire un file JSON in un Pandas DataFrame - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-28T09:19:31+00:00\",\"dateModified\":\"2023-07-28T09:19:31+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Una semplice spiegazione su come convertire un file JSON in un DataFrame panda.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come convertire un file json in un pandas dataframe\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come convertire un file JSON in un Pandas DataFrame - Statorials","description":"Una semplice spiegazione su come convertire un file JSON in un DataFrame panda.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/","og_locale":"it_IT","og_type":"article","og_title":"Come convertire un file JSON in un Pandas DataFrame - Statorials","og_description":"Una semplice spiegazione su come convertire un file JSON in un DataFrame panda.","og_url":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/","og_site_name":"Statorials","article_published_time":"2023-07-28T09:19:31+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/","url":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/","name":"Come convertire un file JSON in un Pandas DataFrame - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-28T09:19:31+00:00","dateModified":"2023-07-28T09:19:31+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Una semplice spiegazione su come convertire un file JSON in un DataFrame panda.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/json-nel-dataframe-panda\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come convertire un file json in un pandas dataframe"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/900"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=900"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/900\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}