python - How can I create an empty Pandas DataFrame with specific columns? -


this question has answer here:

i've got dataframe initialized same columns, doesn't have data:

import pandas pd  data = [] df = pd.dataframe(data, columns=['a', 'b', 'c']) 

but fails error:

traceback (most recent call last):   … valueerror: shape of passed values (0, 0), indices imply (3, 0) 

how can create empty dataframe columns?

as of pandas version 0.16.1, passing data = [] works:

in [85]: df = pd.dataframe([], columns=['a', 'b', 'c'])  in [86]: df out[86]:  empty dataframe columns: [a, b, c] index: [] 

for older versions of pandas, don't pass data:

in [69]: df = pd.dataframe(columns=['a', 'b', 'c'])  in [70]: df out[70]:  empty dataframe columns: [a, b, c] index: [] 

or pass data=none:

in [71]: df = pd.dataframe(none, columns=['a', 'b', 'c'])  in [72]: df out[72]:  empty dataframe columns: [a, b, c] index: [] 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -