title: Trying to Parse JSON using Pandas in the YoutubeAnalytics Api and Convert it CSV
body: <p>I am trying to download my youtube data using the <strong>Youtube Analytics and Reporting API</strong> from here <a href="https://developers.google.com/youtube/analytics/reference/reports/query?apix_params=%7B%22dimensions%22%3A%22day%22%2C%22endDate%22%3A%222020-10-05%22%2C%22ids%22%3A%22channel%3D%3DMINE%22%2C%22metrics%22%3A%22views%2CestimatedMinutesWatched%2CaverageViewDuration%2CaverageViewPercentage%2CsubscribersGained%22%2C%22sort%22%3A%22day%22%2C%22startDate%22%3A%222020-10-01%22%7D#python" rel="nofollow noreferrer">Google Reference</a>. I am using Python code from google to download this data which works fine. The data is retrieved in JSON format As shown below.</p>
  <p>rawdata.json  -</p>
  <pre><code>{
    &quot;kind&quot;: &quot;youtubeAnalytics#resultTable&quot;,
    &quot;columnHeaders&quot;: [
      {
        &quot;name&quot;: &quot;day&quot;,
        &quot;columnType&quot;: &quot;DIMENSION&quot;,
        &quot;dataType&quot;: &quot;STRING&quot;
      },
      {
        &quot;name&quot;: &quot;views&quot;,
        &quot;columnType&quot;: &quot;METRIC&quot;,
        &quot;dataType&quot;: &quot;INTEGER&quot;
      },
      {
        &quot;name&quot;: &quot;estimatedMinutesWatched&quot;,
        &quot;columnType&quot;: &quot;METRIC&quot;,
        &quot;dataType&quot;: &quot;INTEGER&quot;
      },
      {
        &quot;name&quot;: &quot;averageViewDuration&quot;,
        &quot;columnType&quot;: &quot;METRIC&quot;,
        &quot;dataType&quot;: &quot;INTEGER&quot;
      },
      {
        &quot;name&quot;: &quot;averageViewPercentage&quot;,
        &quot;columnType&quot;: &quot;METRIC&quot;,
        &quot;dataType&quot;: &quot;FLOAT&quot;
      },
      {
        &quot;name&quot;: &quot;subscribersGained&quot;,
        &quot;columnType&quot;: &quot;METRIC&quot;,
        &quot;dataType&quot;: &quot;INTEGER&quot;
      }
    ],
    &quot;rows&quot;: [
      [
        &quot;2020-10-01&quot;,
        445,
        1068,
        144,
        38.78,
        3
      ],
      [
        &quot;2020-10-02&quot;,
        406,
        905,
        133,
        34.94,
        2
      ],
      [
        &quot;2020-10-03&quot;,
        466,
        1042,
        134,
        34.77,
        6
      ],
      [
        &quot;2020-10-04&quot;,
        427,
        1006,
        141,
        36.48,
        3
      ],
      [
        &quot;2020-10-05&quot;,
        379,
        964,
        152,
        39.48,
        2
      ]
    ]
  }
  </code></pre>
  <p>I am trying to convert this JSON into CSV format but having no luck so far.</p>
  <p>Here is the python code I am using to normalize and create a data frame but having no luck.</p>
  <pre><code>import json
  import pandas as pd
  from pandas import json_normalize 
  
  with open('rawdata.json') as json_file:
      data = json.load(json_file)
      #print (data)
  
  df = json_normalize(data['rows'])
  print(df)
  </code></pre>
  <p>I am trying to get the final output in this format. <a href="https://i.stack.imgur.com/8sVWF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8sVWF.png" alt="enter image description here" /></a></p>
  <p>Any help or guidance is much appreciated.</p>
  <p>EDIT: Answer by Suraj S. This worked out for me.</p>
  <pre><code>import json
  import pandas as pd
  from pandas import json_normalize 
  
  with open('rawdata.json') as json_file:
      data = json.load(json_file)
      #print (data)
  
  df = pd.DataFrame(data['rows'],columns=['day','views','comments','likes','dislikes','estimatedMinutesWatched','averageViewDuration','subscribersGained'])
  
  print(df)
  </code></pre>