title: How to flatten a column of nested json objects in an already flattened dataframe
body: <p>I have a json file with nested objects which is flattened in a pandas dataframe. There is a single column with nested json objects that I find hard the flatten.</p>
  <p>I have tried many approaches, this is the approach that got me the furthest.</p>
  <p>Help would be greatly appreciated, thank you.</p>
  <p><em>Unfortunately I was unable to find a jsfiddle like alternative for python to provide a working example.</em></p>
  <p>I understand that with the meta parameter of json_normalize I can add columns to my dataframe. But that approach does not work on the unflat column because I only got json_normalize to work well in my setup by setting record_path to 'markets' which is the main json object in my file. So in this setup I am unable to record_path to 'marketStats' and add any relevant columns via the meta parameter.</p>
  <p><strong>Goal</strong></p>
  <p>The goal is to transform one or all json objects in the marketStats object in to columns of the dataframe.</p>
  <p><strong>Code</strong></p>
  <pre><code>with open('Data/20012022.json') as file:
  data = json.loads(file.read())
  
  # Flatten data
  df0 = pd.json_normalize(
        data, 
        record_path =['markets']
  )
  
  df0.head(3)
  </code></pre>
  <p><strong>Screenshot</strong></p>
  <p>This is a screenshot of what the table currently looks like, the marketStats column contains nested json.</p>
  <p><a href="https://i.stack.imgur.com/ssTdz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ssTdz.png" alt="enter image description here" /></a></p>
  <p><strong>Data</strong></p>
  <p>This a snippet from the json file. `</p>
  <pre><code>{
    &quot;markets&quot;: [
      {
        &quot;id&quot;: 335,
        &quot;baseCurrency&quot;: &quot;eth&quot;,
        &quot;quoteCurrency&quot;: &quot;btc&quot;,
        &quot;exchangeName&quot;: &quot;Binance&quot;,
        &quot;exchangeCode&quot;: &quot;BINA&quot;,
        &quot;longName&quot;: &quot;BTC-ETH&quot;,
        &quot;marketName&quot;: &quot;btc-eth&quot;,
        &quot;symbol&quot;: &quot;ETHBTC&quot;,
        &quot;volume&quot;: &quot;40624.5823&quot;,
        &quot;quoteVolume&quot;: &quot;3026.13646935&quot;,
        &quot;btcVolume&quot;: &quot;3026.13646935&quot;,
        &quot;usdVolume&quot;: &quot;127009429.050524367&quot;,
        &quot;currentPrice&quot;: 0.074681,
        &quot;latestBase&quot;: {
          &quot;id&quot;: 161774475,
          &quot;time&quot;: 1639576800,
          &quot;date&quot;: &quot;2021-12-15T14:00:00.000+00:00&quot;,
          &quot;price&quot;: &quot;0.077653&quot;,
          &quot;lowestPrice&quot;: &quot;0.0729&quot;,
          &quot;bounce&quot;: &quot;6.283&quot;,
          &quot;currentDrop&quot;: &quot;-3.8272829124438206&quot;,
          &quot;crackedAt&quot;: &quot;2022-01-07T03:00:00.000Z&quot;,
          &quot;respectedAt&quot;: &quot;2022-01-15T15:00:00.000Z&quot;,
          &quot;isLowest&quot;: false
        },
        &quot;marketStats&quot;: [
          {
            &quot;algorithm&quot;: &quot;original&quot;,
            &quot;ratio&quot;: &quot;50.0&quot;,
            &quot;medianDrop&quot;: &quot;-4.08&quot;,
            &quot;medianBounce&quot;: &quot;5.51&quot;,
            &quot;hoursToRespected&quot;: 106,
            &quot;crackedCount&quot;: 2,
            &quot;respectedCount&quot;: 1
          },
          {
            &quot;algorithm&quot;: &quot;day_trade&quot;,
            &quot;ratio&quot;: &quot;100.0&quot;,
            &quot;medianDrop&quot;: &quot;-6.12&quot;,
            &quot;medianBounce&quot;: &quot;6.28&quot;,
            &quot;hoursToRespected&quot;: 204,
            &quot;crackedCount&quot;: 1,
            &quot;respectedCount&quot;: 1
          },
          {
            &quot;algorithm&quot;: &quot;conservative&quot;,
            &quot;ratio&quot;: &quot;100.0&quot;,
            &quot;medianDrop&quot;: &quot;-6.12&quot;,
            &quot;medianBounce&quot;: &quot;8.38&quot;,
            &quot;hoursToRespected&quot;: 204,
            &quot;crackedCount&quot;: 1,
            &quot;respectedCount&quot;: 1
          },
          {
            &quot;algorithm&quot;: &quot;position&quot;,
            &quot;ratio&quot;: &quot;50.0&quot;,
            &quot;medianDrop&quot;: &quot;-6.12&quot;,
            &quot;medianBounce&quot;: &quot;6.19&quot;,
            &quot;hoursToRespected&quot;: 204,
            &quot;crackedCount&quot;: 2,
            &quot;respectedCount&quot;: 1
          },
          {
            &quot;algorithm&quot;: &quot;hodloo&quot;,
            &quot;ratio&quot;: &quot;50.0&quot;,
            &quot;medianDrop&quot;: &quot;-3.29&quot;,
            &quot;medianBounce&quot;: &quot;0.0&quot;,
            &quot;hoursToRespected&quot;: 225,
            &quot;crackedCount&quot;: 4,
            &quot;respectedCount&quot;: 2
          }
        ]
      },
      {
        &quot;id&quot;: 337,
        &quot;baseCurrency&quot;: &quot;ltc&quot;,
        &quot;quoteCurrency&quot;: &quot;btc&quot;,
        &quot;exchangeName&quot;: &quot;Binance&quot;,
        &quot;exchangeCode&quot;: &quot;BINA&quot;,
        &quot;longName&quot;: &quot;BTC-LTC&quot;,
        &quot;marketName&quot;: &quot;btc-ltc&quot;,
        &quot;symbol&quot;: &quot;LTCBTC&quot;,
        &quot;volume&quot;: &quot;68309.637&quot;,
        &quot;quoteVolume&quot;: &quot;223.79294524&quot;,
        &quot;btcVolume&quot;: &quot;223.79294524&quot;,
        &quot;usdVolume&quot;: &quot;9392773.4219378968&quot;,
        &quot;currentPrice&quot;: 0.003275,
        &quot;latestBase&quot;: {
          &quot;id&quot;: 163982984,
          &quot;time&quot;: 1642374000,
          &quot;date&quot;: &quot;2022-01-16T23:00:00.000+00:00&quot;,
          &quot;price&quot;: &quot;0.003346&quot;,
          &quot;lowestPrice&quot;: &quot;0.00322&quot;,
          &quot;bounce&quot;: &quot;3.839&quot;,
          &quot;currentDrop&quot;: &quot;-2.1219366407650926&quot;,
          &quot;crackedAt&quot;: &quot;2022-01-18T23:00:00.000Z&quot;,
          &quot;respectedAt&quot;: null,
          &quot;isLowest&quot;: false
        },
        &quot;marketStats&quot;: [
          {
            &quot;algorithm&quot;: &quot;original&quot;,
            &quot;ratio&quot;: &quot;57.14&quot;,
            &quot;medianDrop&quot;: &quot;-3.28&quot;,
            &quot;medianBounce&quot;: &quot;3.84&quot;,
            &quot;hoursToRespected&quot;: 186,
            &quot;crackedCount&quot;: 7,
            &quot;respectedCount&quot;: 4
          },
          {
            &quot;algorithm&quot;: &quot;day_trade&quot;,
            &quot;ratio&quot;: &quot;0.0&quot;,
            &quot;medianDrop&quot;: &quot;0.0&quot;,
            &quot;medianBounce&quot;: &quot;5.68&quot;,
            &quot;hoursToRespected&quot;: 0,
            &quot;crackedCount&quot;: 1,
            &quot;respectedCount&quot;: 0
          },
          {
            &quot;algorithm&quot;: &quot;conservative&quot;,
            &quot;ratio&quot;: &quot;0.0&quot;,
            &quot;medianDrop&quot;: &quot;0.0&quot;,
            &quot;medianBounce&quot;: &quot;5.68&quot;,
            &quot;hoursToRespected&quot;: 0,
            &quot;crackedCount&quot;: 1,
            &quot;respectedCount&quot;: 0
          },
          {
            &quot;algorithm&quot;: &quot;position&quot;,
            &quot;ratio&quot;: &quot;0.0&quot;,
            &quot;medianDrop&quot;: &quot;0.0&quot;,
            &quot;medianBounce&quot;: &quot;8.16&quot;,
            &quot;hoursToRespected&quot;: 0,
            &quot;crackedCount&quot;: 1,
            &quot;respectedCount&quot;: 0
          },
          {
            &quot;algorithm&quot;: &quot;hodloo&quot;,
            &quot;ratio&quot;: &quot;75.0&quot;,
            &quot;medianDrop&quot;: &quot;-3.7&quot;,
            &quot;medianBounce&quot;: &quot;0.0&quot;,
            &quot;hoursToRespected&quot;: 35,
            &quot;crackedCount&quot;: 4,
            &quot;respectedCount&quot;: 3
          }
        ]
      },
      {
        &quot;id&quot;: 339,
        &quot;baseCurrency&quot;: &quot;bnb&quot;,
        &quot;quoteCurrency&quot;: &quot;btc&quot;,
        &quot;exchangeName&quot;: &quot;Binance&quot;,
        &quot;exchangeCode&quot;: &quot;BINA&quot;,
        &quot;longName&quot;: &quot;BTC-BNB&quot;,
        &quot;marketName&quot;: &quot;btc-bnb&quot;,
        &quot;symbol&quot;: &quot;BNBBTC&quot;,
        &quot;volume&quot;: &quot;154576.177&quot;,
        &quot;quoteVolume&quot;: &quot;1724.66664804&quot;,
        &quot;btcVolume&quot;: &quot;1724.66664804&quot;,
        &quot;usdVolume&quot;: &quot;72385673.4448901928&quot;,
        &quot;currentPrice&quot;: 0.01099,
        &quot;latestBase&quot;: {
          &quot;id&quot;: 163753765,
          &quot;time&quot;: 1642068000,
          &quot;date&quot;: &quot;2022-01-13T10:00:00.000+00:00&quot;,
          &quot;price&quot;: &quot;0.01093&quot;,
          &quot;lowestPrice&quot;: &quot;0.01093&quot;,
          &quot;bounce&quot;: &quot;3.102&quot;,
          &quot;currentDrop&quot;: &quot;0.5489478499542543&quot;,
          &quot;crackedAt&quot;: null,
          &quot;respectedAt&quot;: null,
          &quot;isLowest&quot;: false
        },
        &quot;marketStats&quot;: [
          {
            &quot;algorithm&quot;: &quot;original&quot;,
            &quot;ratio&quot;: &quot;100.0&quot;,
            &quot;medianDrop&quot;: &quot;-7.18&quot;,
            &quot;medianBounce&quot;: &quot;4.34&quot;,
            &quot;hoursToRespected&quot;: 62,
            &quot;crackedCount&quot;: 2,
            &quot;respectedCount&quot;: 2
          },
          {
            &quot;algorithm&quot;: &quot;day_trade&quot;,
            &quot;ratio&quot;: &quot;100.0&quot;,
            &quot;medianDrop&quot;: &quot;-6.19&quot;,
            &quot;medianBounce&quot;: &quot;4.3&quot;,
            &quot;hoursToRespected&quot;: 63,
            &quot;crackedCount&quot;: 1,
            &quot;respectedCount&quot;: 1
          },
          {
            &quot;algorithm&quot;: &quot;conservative&quot;,
            &quot;ratio&quot;: &quot;66.67&quot;,
            &quot;medianDrop&quot;: &quot;-3.15&quot;,
            &quot;medianBounce&quot;: &quot;4.05&quot;,
            &quot;hoursToRespected&quot;: 62,
            &quot;crackedCount&quot;: 3,
            &quot;respectedCount&quot;: 2
          },
          {
            &quot;algorithm&quot;: &quot;position&quot;,
            &quot;ratio&quot;: &quot;100.0&quot;,
            &quot;medianDrop&quot;: &quot;-3.15&quot;,
            &quot;medianBounce&quot;: &quot;4.46&quot;,
            &quot;hoursToRespected&quot;: 60,
            &quot;crackedCount&quot;: 2,
            &quot;respectedCount&quot;: 2
          },
          {
            &quot;algorithm&quot;: &quot;hodloo&quot;,
            &quot;ratio&quot;: &quot;100.0&quot;,
            &quot;medianDrop&quot;: &quot;-7.46&quot;,
            &quot;medianBounce&quot;: &quot;0.0&quot;,
            &quot;hoursToRespected&quot;: 62,
            &quot;crackedCount&quot;: 5,
            &quot;respectedCount&quot;: 5
          }
        ]
      }
    ]
  }
  </code></pre>