Skip to content

DataFrame populated with the letter "n" when no data passed and dtype is specified as str #9428

Closed
@ajcr

Description

@ajcr

This is discussed on Stack Overflow here.

When constructing a DataFrame with the dtype as str but not passing in any data (just an index), the resulting DataFrame is filled with the letter n:

In [61]: pd.DataFrame(index=range(2), columns=[0], dtype=str)
Out[61]: 
   0
0  n
1  n

This is contrary to the behaviour of Series when no data is passed in:

In [62]: pd.Series(index=range(2), dtype=str)
Out[62]: 
0    NaN
1    NaN
dtype: object

It would be logical for the DataFrame to be populated with NaN in this instance too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions