Here are a few options you could choose:
import numpy as np import pandas as pd index = ['x', 'y'] columns = ['a','b','c']
Each of the above options gives the same result.
abc x 0 0 0 y 0 0 0
with dtypes:
a int32 b float32 c float32 dtype: object
Why pd.DataFrame(values, index=index, columns=columns) creates a DataFrame with NaN :
values is a structured array with column names f0 , f1 , f2 :
In [171]: values Out[172]: array([(0, 0.0, 0.0), (0, 0.0, 0.0)], dtype=[('f0', '<i4'), ('f1', '<f4'), ('f2', '<f4')])
If you pass the argument columns=['a', 'b', 'c'] to pd.DataFrame , then Pandas will look for columns with these names in a structured array of values . When these columns are not found, Pandas places a NaN in the DataFrame to represent the missing values.
unutbu Feb 08 '14 at 14:25 2014-02-08 14:25
source share