Skip to content

case insensitive bool parsing #1295

Closed
Closed
@changhiskhan

Description

@changhiskhan

From mailing list:

This is something that surprised me.
When reading from csv the values "True" and "False" are converted to bool, while "TRUE" and "FALSE"' to object
Using a converter {...: np.bool} I could take it into account.
Is it useful to take more possibilities into account knowing that there are a lot of possibilies True/False, Yes/No, ....?

In [19]: data = '''A;B
....: True;False
....: False;True'''
In [20]: df = pd.read_csv(StringIO(data), sep=';')
In [22]: df.dtypes
Out[22]:
A bool
B bool

In [23]: data = '''A;B
....: TRUE;FALSE
....: FALSE;TRUE'''

In [24]: df = pd.read_csv(StringIO(data), sep=';')

In [25]: df.dtypes
Out[25]:
A object
B object

In [27]: df = pd.read_csv(StringIO(data), sep=';', converters={'A':np.bool})

In [28]: df.dtypes
Out[28]:
A bool
B object

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementIO DataIO issues that don't fit into a more specific label

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

        翻译: