Skip to content

Tag: python

Reverse a get_dummies encoding in pandas

Column names are: ID,1,2,3,4,5,6,7,8,9. The col values are either 0 or 1 My dataframe looks like this: I want the column names in front of the ID where the value in a row is 1. The Dataframe i want should look like this: Please help me in this, Thanks in advance Answer set_index + stack, stack will dropna by …

What does a backslash mean in a string literal?

I made a list of strings like this: But if I try to print it, I get a very different looking result: Why does this happen? Does the character have some special meaning here? Answer The backslash is used to escape special (unprintable) characters in string literals. n is for newline, t for tab, f for a form-f…

convert dataframe row to dict

I have datarame like the sample data below. I’m trying to convert one row from the dataframe in to a dict like the desired output below. But when I use to_dict I get the indice along with the column value. Does anyone know how to get convert the row to a dict like the desired output? Any tips greatly ap…

Authentication plugin ‘caching_sha2_password’ is not supported

I am trying to connect to a MySQL server with python connector. I created a new user lcherukuri with the authentication plugin mysql_native_password. But I got the error mysql.connector.errors.NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported Can someone help me? An…