Repository: pandas-dev/pandas

Issue:
json_normalize should be able to accept an empty list
#### Code Sample, a copy-pastable example if possible

```python-traceback
In[21]: pandas.io.json.json_normalize([])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-21-1bd834af8a9b> in <module>()
----> 1 pandas.io.json.json_normalize([])

/usr/local/lib/python3.6/site-packages/pandas/io/json.py in json_normalize(data, record_path, meta, meta_prefix, record_prefix)
    791 
    792     if record_path is None:
--> 793         if any([isinstance(x, dict) for x in compat.itervalues(data[0])]):
    794             # naive normalization, this is idempotent for flat records
    795             # and potentially will inflate the data considerably for

IndexError: list index out of range
```

#### Problem description

This should probably return an empty dataframe when the list is empty, based on `len(data)` being 0.

#### Expected Output

```python
>>> pandas.io.json.json_normalize([])

Empty DataFrame
Columns: []
Index: []
```

Admittedly, this could be a series too -- I was using this across several collections and noticed I had to code around when some entries were empty.

#### Output of ``pd.show_versions()``

<details>

```
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Darwin
OS-release: 16.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 34.1.0
Cython: None
numpy: 1.12.0
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.2.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8.1
boto: None
pandas_datareader: None
```

</details>



Discussion:
yep, I think returning an empty ``DataFrame`` would be fine. PR's welcome!

Resolving patch:
diff --git a/pandas/io/json/normalize.py b/pandas/io/json/normalize.py
--- a/pandas/io/json/normalize.py
+++ b/pandas/io/json/normalize.py
@@ -157,6 +157,9 @@ def _pull_field(js, spec):
 
         return result
 
+    if isinstance(data, list) and len(data) is 0:
+        return DataFrame()
+
     # A bit of a hackjob
     if isinstance(data, dict):
         data = [data]


Test patch:
diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py
--- a/pandas/tests/io/json/test_normalize.py
+++ b/pandas/tests/io/json/test_normalize.py
@@ -62,6 +62,11 @@ def test_simple_normalize(self):
 
         tm.assert_frame_equal(result, expected)
 
+    def test_empty_array(self):
+        result = json_normalize([])
+        expected = DataFrame()
+        tm.assert_frame_equal(result, expected)
+
     def test_more_deeply_nested(self):
         data = [{'country': 'USA',
                  'states': [{'name': 'California',