How-to articles, tricks, and solutions about PYTHON

Check if a word is in a string in Python

You can use the in keyword to check if a word is in a string in Python.

Check if something is (not) in a list in Python

In Python, you can check if an item is in a list using the in keyword.

Checking whether a variable is an integer or not

In Python, you can check if a variable is an integer using the isinstance() function.

Class (static) variables and methods

In Python, class variables are variables that are shared by all instances of a class.

Combine two columns of text in pandas dataframe

In pandas, you can use the str.cat() function to combine the values of two columns of text into a single column.

Convert a String representation of a Dictionary to a dictionary

You can use the json module in Python to convert a string representation of a dictionary to a dictionary.

Convert a Unicode string to a string in Python (containing extra symbols)

You can use the .encode() method to convert a Unicode string to a string containing extra symbols in Python.

Convert all strings in a list to int

In Python, you can use the map() function along with the built-in int() function to convert all strings in a list to integers.

Convert bytes to a string

To convert a byte object into a string, you can use the decode() method.

Convert columns to string in Pandas

To convert all columns in a Pandas DataFrame to strings, you can use the following code snippet:

Convert date to datetime in Python

You can convert a date to datetime in Python using the datetime module.

Convert floats to ints in Pandas?

To convert floats to integers in Pandas, you can use the astype() function.

Convert hex string to integer in Python

You can use the int() function in Python to convert a hex string to an integer.

Convert integer to string in Python

To convert an integer to a string in Python, use the str() function.

Convert list of dictionaries to a pandas DataFrame

Here is an example of how to convert a list of dictionaries to a pandas DataFrame:

Convert list to tuple in Python

You can convert a list to a tuple in Python by using the built-in tuple() function.

Convert Pandas Column to DateTime

To convert a column in a Pandas DataFrame to a datetime data type, you can use the pandas.to_datetime() function.

Convert pandas dataframe to NumPy array

In pandas, you can convert a DataFrame to a NumPy array by using the values attribute.

Convert Python dict into a dataframe

You can use the Pandas library to convert a Python dictionary into a dataframe.

Convert string "Jun 1 2005 1:33PM" into datetime

To convert the string "Jun 1 2005 1:33PM" into a datetime object, you can use the datetime module in the Python standard library.

Converting a Pandas GroupBy output from Series to DataFrame

Here is an example code snippet that demonstrates how to convert the output of a Pandas GroupBy operation from a Series to a DataFrame:

Converting Dictionary to List?

In Python, you can convert a dictionary to a list of its keys or values using the keys() and values() methods, respectively.

Converting from a string to boolean in Python

In Python, you can use the bool() function to convert a string to a boolean.

Converting unix timestamp string to readable date

You can use the datetime module in Python to convert a UNIX timestamp string to a readable date.