extract files inside zip sub folders with python zipfile
<p>i have a zip folder that contains files and child zip folders. I am able to read the files placed in the parent folder but how can i get to the files inside the child zip folders? here is my code to get the files inside the parent folder</p>

<pre><code>from io import BytesIO
import pandas as pd
import requests
import zipfile
url1 = 'https://www.someurl.com/abc.zip'
r = requests.get(url1)
z = zipfile.ZipFile(BytesIO(r.content))    
temp  = pd.read_csv(z.open('mno.csv')
</code></pre>

<p>my question is, if lets say, I have a child sub folder </p>

<pre><code>xyz.zip 
</code></pre>

<p>containing file</p>

<pre><code>pqr.csv
</code></pre>

<p>how can I read this file</p>

<p>Use another <code>BytesIO</code> object to open the contained zipfile</p>

<pre><code>from io import BytesIO
import pandas as pd
import requests
import zipfile

# Read outer zip file
url1 = 'https://www.someurl.com/abc.zip'
r = requests.get(url1)
z = zipfile.ZipFile(BytesIO(r.content))

# lets say the archive is:
#     zippped_folder/pqr.zip (which contains pqr.csv)

# Read contained zip file
pqr_zip = zipfile.ZipFile(BytesIO(z.open('zippped_folder/pqr.zip')))
temp = pd.read_csv(pqr_zip.open('prq.csv'))
</code></pre>

python pandas zipfile