Skip to content

BUG: Apply pd.get_dummies() on string type columns of pandas dataframe do nothing? #44965

Closed
@stevesolun

Description

@stevesolun

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

I have the following dataframe:

df = pd.DataFrame({'a': [6.6, -5.2, 2.1, 3.3, 1.1],
              'b': ['a', 'a', 'c', 'b', 'a'],
              'c': ['kfr', 'kfr', 'lu', 'ku', 'lu'],
              'd': ['t', 's', 's', 't', 'a']})

All the dtypes (columns b, c, d) are of type string.

If I call df = df.convert_dtypes(), and then call pd.get_dummies(), nothing happens:

df = pd.DataFrame({'a': [6.6, -5.2, 2.1, 3.3, 1.1],
              'b': ['a', 'a', 'c', 'b', 'a'],
              'c': ['kfr', 'kfr', 'lu', 'ku', 'lu'],
              'd': ['t', 's', 's', 't', 'a']})
df = df.convert_dtypes()
pd.get_dummies(df)

But if I will change the df.convert_dtypes() to df.convert_dtypes(convert_string=False) it will work as expected.
Why is this happening? Is it a bug?

Expected Behavior

pandas pd.get_dummies() should work on strings columns dtype also.

Installed Versions

1.3.5

Metadata

Metadata

Assignees

Labels

AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBugStringsString extension data type and string data

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions