<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from pandas.io.json import json_normalize

json_normalize({'A': {'B': [{'X': 1, 'Y': 2}, {'X': 3, 'Y': 4}]}}, ['A', 'B'])"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">io</span>.<span class="pl-s1">json</span> <span class="pl-k">import</span> <span class="pl-s1">json_normalize</span>

<span class="pl-en">json_normalize</span>({<span class="pl-s">'A'</span>: {<span class="pl-s">'B'</span>: [{<span class="pl-s">'X'</span>: <span class="pl-c1">1</span>, <span class="pl-s">'Y'</span>: <span class="pl-c1">2</span>}, {<span class="pl-s">'X'</span>: <span class="pl-c1">3</span>, <span class="pl-s">'Y'</span>: <span class="pl-c1">4</span>}]}}, [<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>])</pre></div>
<p dir="auto">Note: change from <code class="notranslate">json_normalize({'A': {'B': [1, 2]}}, ['A', 'B'])</code> to distinguish from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="335086132" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/21608" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/21608/hovercard" href="https://github.com/pandas-dev/pandas/issues/21608">#21608</a></p>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The above code throws a <code class="notranslate">TypeError</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;C:\Python36\lib\site-packages\pandas\io\json\normalize.py&quot;, line 257, in json_normalize
    _recursive_extract(data, record_path, {}, level=0)
  File &quot;C:\Python36\lib\site-packages\pandas\io\json\normalize.py&quot;, line 230, in _recursive_extract
    seen_meta, level=level + 1)
  File &quot;C:\Python36\lib\site-packages\pandas\io\json\normalize.py&quot;, line 233, in _recursive_extract
    recs = _pull_field(obj, path[0])
  File &quot;C:\Python36\lib\site-packages\pandas\io\json\normalize.py&quot;, line 180, in _pull_field
    result = result[spec]
TypeError: string indices must be integers"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Python36\lib\site-packages\pandas\io\json\normalize.py", line 257, in json_normalize
    _recursive_extract(data, record_path, {}, level=0)
  File "C:\Python36\lib\site-packages\pandas\io\json\normalize.py", line 230, in _recursive_extract
    seen_meta, level=level + 1)
  File "C:\Python36\lib\site-packages\pandas\io\json\normalize.py", line 233, in _recursive_extract
    recs = _pull_field(obj, path[0])
  File "C:\Python36\lib\site-packages\pandas\io\json\normalize.py", line 180, in _pull_field
    result = result[spec]
TypeError: string indices must be integers
</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<table role="table">
<thead>
<tr>
<th></th>
<th>X</th>
<th>Y</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
<p dir="auto">pandas: 0.23.1<br>
pytest: 3.6.1<br>
pip: 10.0.1<br>
setuptools: 28.8.0<br>
Cython: None<br>
numpy: 1.14.2<br>
scipy: None<br>
pyarrow: None<br>
xarray: None<br>
IPython: 6.3.1<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.7.2<br>
pytz: 2018.4<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: 4.6.0<br>
html5lib: 1.0.1<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.10<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">Current conversion of R objects into Python usng <code class="notranslate">pandas2ri.ri2py</code> does not work for the <code class="notranslate">&lt;class 'rpy2.robjects.vectors.ListVector'&gt;</code> object. As noted <a href="http://pandas.pydata.org/pandas-docs/stable/r_interface.html" rel="nofollow">here</a>, <code class="notranslate">pandas2ri.py2ri()</code> and <code class="notranslate">pandas2ri.ri2py()</code> are current methods to handle conversion. However, previous deprecated  <code class="notranslate">com.convert_robj()</code> correctly converts the R object to Python dictionary:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import rpy2
from rpy2.robjects.numpy2ri import numpy2ri
from rpy2.robjects.packages import importr
import numpy as np

# FISHER EXACT TEST EXAMPLE
cont = np.reshape(np.arange(0,4), (2,2))  
statspackage = importr('stats',  robject_translations={'format_perc': '_format_perc'})
result = statspackage.fisher_test(numpy2ri(cont), simulate_p_value = True, B = 100)

# DEPRECATED CONVERSION
import pandas.rpy.common as com
pyresultdict = com.convert_robj(result)

print(type(pyresultdict))   # PYTHON DICTIONARY TYPE

# CURRENT CONVERSION
from rpy2.robjects import pandas2ri
pandas2ri.activate()
pyresultdict = pandas2ri.ri2py(result)

print(type(pyresultdict))   # REMAINS R LISTVECTOR TYPE"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">rpy2</span>
<span class="pl-k">from</span> <span class="pl-s1">rpy2</span>.<span class="pl-s1">robjects</span>.<span class="pl-s1">numpy2ri</span> <span class="pl-k">import</span> <span class="pl-s1">numpy2ri</span>
<span class="pl-k">from</span> <span class="pl-s1">rpy2</span>.<span class="pl-s1">robjects</span>.<span class="pl-s1">packages</span> <span class="pl-k">import</span> <span class="pl-s1">importr</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-c"># FISHER EXACT TEST EXAMPLE</span>
<span class="pl-s1">cont</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">reshape</span>(<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">0</span>,<span class="pl-c1">4</span>), (<span class="pl-c1">2</span>,<span class="pl-c1">2</span>))  
<span class="pl-s1">statspackage</span> <span class="pl-c1">=</span> <span class="pl-en">importr</span>(<span class="pl-s">'stats'</span>,  <span class="pl-s1">robject_translations</span><span class="pl-c1">=</span>{<span class="pl-s">'format_perc'</span>: <span class="pl-s">'_format_perc'</span>})
<span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">statspackage</span>.<span class="pl-en">fisher_test</span>(<span class="pl-en">numpy2ri</span>(<span class="pl-s1">cont</span>), <span class="pl-s1">simulate_p_value</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>, <span class="pl-v">B</span> <span class="pl-c1">=</span> <span class="pl-c1">100</span>)

<span class="pl-c"># DEPRECATED CONVERSION</span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">rpy</span>.<span class="pl-s1">common</span> <span class="pl-k">as</span> <span class="pl-s1">com</span>
<span class="pl-s1">pyresultdict</span> <span class="pl-c1">=</span> <span class="pl-s1">com</span>.<span class="pl-en">convert_robj</span>(<span class="pl-s1">result</span>)

<span class="pl-en">print</span>(<span class="pl-en">type</span>(<span class="pl-s1">pyresultdict</span>))   <span class="pl-c"># PYTHON DICTIONARY TYPE</span>

<span class="pl-c"># CURRENT CONVERSION</span>
<span class="pl-k">from</span> <span class="pl-s1">rpy2</span>.<span class="pl-s1">robjects</span> <span class="pl-k">import</span> <span class="pl-s1">pandas2ri</span>
<span class="pl-s1">pandas2ri</span>.<span class="pl-en">activate</span>()
<span class="pl-s1">pyresultdict</span> <span class="pl-c1">=</span> <span class="pl-s1">pandas2ri</span>.<span class="pl-en">ri2py</span>(<span class="pl-s1">result</span>)

<span class="pl-en">print</span>(<span class="pl-en">type</span>(<span class="pl-s1">pyresultdict</span>))   <span class="pl-c"># REMAINS R LISTVECTOR TYPE</span></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# Expected Output
&lt;class 'dict'&gt;
&lt;class 'dict'&gt;"><pre class="notranslate"><span class="pl-c"># Expected Output</span>
<span class="pl-c1">&lt;</span><span class="pl-k">class</span> <span class="pl-s">'dict'</span><span class="pl-c1">&gt;</span>
<span class="pl-c1">&lt;</span><span class="pl-k">class</span> <span class="pl-s">'dict'</span><span class="pl-c1">&gt;</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# output of rpy2.__version__
2.5.4

# output of  pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.1.final.0
python-bits: 64
OS: Windows
OS-release: 8
machine: AMD64
processor: Intel64 Family 6 Model 37 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: None
pip: 8.1.0
setuptools: 2.1
Cython: None
numpy: 1.10.4
scipy: 0.17.0
...
"><pre class="notranslate"><code class="notranslate"># output of rpy2.__version__
2.5.4

# output of  pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.1.final.0
python-bits: 64
OS: Windows
OS-release: 8
machine: AMD64
processor: Intel64 Family 6 Model 37 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: None
pip: 8.1.0
setuptools: 2.1
Cython: None
numpy: 1.10.4
scipy: 0.17.0
...

</code></pre></div>