Create Empty Dataframe in Pandas specifying column types

You can use the following:

df = pd.DataFrame({'a': pd.Series(dtype="int"),
                   'b': pd.Series(dtype="str"),
                   'c': pd.Series(dtype="float")})

or more abstractly:

df = pd.DataFrame({c: pd.Series(dtype=t) for c, t in {'a': 'int', 'b': 'str', 'c': 'float'}.items()})

then if you call df you have:

>>> df 
Empty DataFrame 
Columns: [a, b, c]
Index: []

and if you check its types:

>>> df.dtypes
a      int32
b     object
c    float64
dtype: object

Leave a Comment