Skip to content

Default empty DataFrame to dtype=object #1783

Closed
@dalejung

Description

@dalejung

I ran into the following :

import pandas as pd

data = {}
columns = ['symbol', 'price']
df = pd.DataFrame(data, columns=columns)

df.symbol == 'AAPL'
# TypeError: Could not compare <type 'str'> type with Series

The problem being that an empty dataframe's dtype defaults to float. I've adjusted for it by checking the len of data and setting the dtype to object when at 0. But I feel like an empty DataFrame should act like an empty list, valid for all list operations. Which in lieu of #549, means casting the widest net possible with dtype=object.

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