-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Apply pd.get_dummies() on string type columns of pandas dataframe do nothing? #44965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
when you write the pd.get_dummies() without the dataframe inside the bracket, it will throw some errors. The best you can do is create a variable say ,,"dummies" |
What does it do to fix the bug? |
It will create dummies for data series in a dataframe. It will convert the
strings into zeros and ones .
…On Tue, Dec 21, 2021, 12:37 PM Steve Solun ***@***.***> wrote:
when you write the pd.get_dummies() without the dataframe inside the
bracket, it will throw some errors. The best you can do is create a
variable say ,,"dummies" dummies=pd.get_dummies(name_of_dataframe)
What does it do to fix the bug?
—
Reply to this email directly, view it on GitHub
<#44965 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMO3FYBLB6FHNK7MYILSQ5LUSBDFNANCNFSM5KLF6V6A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
|
Just write this code: |
I am sorry but it's not the problem here... |
For your case, I think it is not possible to convert strings to integers, float, or even boolean. However, you can convert an integer to float and vice versa. |
Did you run my example? |
Yes. I did run your example. could you please send a screenshot a code so that i could have a look at it |
I am sorry but if you were able to reproduce the issue, can you please suggest a fix? You are one of the pandas developers? |
I am aspiring to become one. I started learning data science recently.
…On Wed, Dec 22, 2021, 5:46 PM Steve Solun ***@***.***> wrote:
I am sorry but if you were able to reproduce the issue, can you please
suggest a fix? You are one of the pandas developers?
Maybe we can create a Zoom call?
—
Reply to this email directly, view it on GitHub
<#44965 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMO3FYASRMR2AZTTNT34T5TUSHQETANCNFSM5KLF6V6A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hi @stevesolun I think @cheruiyot-amon 's point is that your example doesn't run as it's written - in order to expedite resolution, could you fix it up so it can be easily copy-and-pasted please? |
@MarcoGorelli sure. Done |
To minimize this >>> df = pd.DataFrame({'a': ['a', 'b']})
>>> print(pd.get_dummies(df))
a_a a_b
0 1 0
1 0 1
>>> print(pd.get_dummies(df.convert_dtypes()))
a
0 a
1 b |
I see - thanks for the report, and @asishm for the minimal code ! |
Issue is because pandas/pandas/core/reshape/reshape.py Line 913 in a3c0e7b
|
@asishm @lithomas1 thanks a lot! |
take |
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:
All the dtypes (columns b, c, d) are of type string.
If I call
df = df.convert_dtypes()
, and then callpd.get_dummies()
, nothing happens:But if I will change the
df.convert_dtypes()
todf.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
The text was updated successfully, but these errors were encountered: