Skip to content

Tag: python

Convert pandas DataFrame to a nested dict

I’m Looking for a generic way of turning a DataFrame to a nested dictionary This is a sample data frame The number of columns may differ and so does the column names. like this : What is best way to achieve this ? closest I got was with the zip function but haven’t managed to make it work for more

Python: launch default mail client on the system

I’m fairly new to Python and I’m trying to write a plugin for a text editor. I want to know if there is a way to launch default system E-Mail client from python code. Answer With pywin32: Update Ah, I misread your question and presumed you’re on Win platform. A platform independent solution …

Using len for text but discarding spaces in the count

So, I am trying to create a program which counts the number of characters in a string which the user inputs, but I want to discard any spaces that the user enters. Using this, I can get the number of the characters in each word, without spaces, but I don’t know how to add each number together and print …

How to check if a string is a valid regex in Python?

In Java, I could use the following function to check if a string is a valid regex (source): Is there a Python equivalent of the Pattern.compile() and PatternSyntaxException? If so, what is it? Answer Similar to Java. Use re.error exception: exception re.error Exception raised when a string passed to one of th…

Is there a way to clear your printed text in python?

I have wanted for a long time to find out how to clear something like print(“example”) in python, but I cant seem to find anyway or figure anything out. Now I need to clear it, and write some new text. It would print. Hey But I want to clear the “Hey” so the user shouldnt look at both …

Django-queryset join without foreignkey

model.py What I want is to get id_noga where dzienrok=1234. I know that dziens should be but it isn’t and I can’t change that. Normally I would use something like but I don’t know how to join and filter those tables without foreignkey. Answer It’s possible to join two tables by perform…