Most viewed questions in Python

0 votes
1 answer

Pandas DataFrames in a loop, df.to_csv()

can you try something like this? not ...READ MORE

Sep 25, 2018 in Python by Priyaj
• 58,090 points
9,903 views
0 votes
1 answer

How to execute a Python script from the Django shell?

Hello @kartik, The << part is wrong, use < instead: $ ./manage.py shell ...READ MORE

Jun 22, 2020 in Python by Niroj
• 82,880 points
9,814 views
0 votes
1 answer

How can I get the absolute URL (with domain) in Django?

Hello @kartik, Use handy request.build_absolute_uri() method on request, pass it ...READ MORE

Aug 6, 2020 in Python by Niroj
• 82,880 points
9,765 views
0 votes
1 answer

How to remove all characters before a specific character in Python?

Use re.sub. Just match all the chars ...READ MORE

Feb 27, 2019 in Python by SDeb
• 13,300 points
9,739 views
0 votes
1 answer

How to expire session due to inactivity in Django?

Hello @kartik, Expire the session on browser close ...READ MORE

Aug 13, 2020 in Python by Niroj
• 82,880 points
9,695 views
0 votes
2 answers

How to add image file in html using python

Hi, I have implemented as below from robot.api import ...READ MORE

Feb 9, 2021 in Python by anonymous
9,694 views
0 votes
1 answer

How to convert datetime.date to UTC timestamp in Python

In Python 3 (< 3.3) From the docs ...READ MORE

Oct 31, 2018 in Python by Priyaj
• 58,090 points
9,622 views
0 votes
0 answers

How to write df to excel without attribute error, and how to add 2 header columns (1 header, 1 units)

Hi, I am very new to Python ...READ MORE

Jun 3, 2020 in Python by Edureka
• 120 points

edited Jun 5, 2020 by Gitika 9,596 views
0 votes
1 answer

Python using basicConfig method to log to console and file

Try this working fine(tested in python 2.7) ...READ MORE

Aug 27, 2018 in Python by Priyaj
• 58,090 points
9,583 views
+1 vote
1 answer

How to convert records from csv to a list in Python?

If you are using Python 3.x then ...READ MORE

Jun 25, 2019 in Python by Arvind
• 3,040 points

edited Jun 26, 2019 by Kalgi 9,550 views
0 votes
1 answer

How do I draw a semi-circle only using turtle - Python

Try this: import turtle turtle = turtle.Pen() turtle.left(90) for x in ...READ MORE

Jul 6, 2019 in Python by Bheem
9,439 views
0 votes
1 answer

How can “list_display” in a Django ModelAdmin display attributes of ForeignKey fields?

Hello @kartik, As another option, you can do ...READ MORE

Jun 29, 2020 in Python by Niroj
• 82,880 points
9,382 views
+1 vote
1 answer

ImportError: DLL load failed: The specified module could not be found.

Hi@akhtar, You may get this error if you ...READ MORE

Jun 22, 2020 in Python by MD
• 95,440 points
9,377 views
0 votes
1 answer

How can I get the domain name of my site within a Django template?

Hello kartik, The variation of the context processor ...READ MORE

Apr 23, 2020 in Python by Niroj
• 82,880 points
9,374 views
0 votes
1 answer

Adding two pandas dataframes

you can try the following: x.add(y, fill_value=0) import pandas ...READ MORE

Feb 12, 2019 in Python by SDeb
• 13,300 points
9,359 views
0 votes
1 answer

AttributeError: module 'http' has no attribute 'client

Hi@akhtar, To avoid this error make sure you ...READ MORE

Apr 22, 2020 in Python by MD
• 95,440 points
9,333 views
0 votes
1 answer

Closest value and its index in a sorted list - Python

You can try this @Mahesh: lst = [ ...READ MORE

May 28, 2019 in Python by Sai
9,309 views
0 votes
1 answer

How to compare two JSON objects with the same elements in a different order equal?

Hello @kartik, If you want two objects with ...READ MORE

Aug 7, 2020 in Python by Niroj
• 82,880 points
9,275 views
0 votes
1 answer

Pyplot error "only size-1 arrays can be converted to Python scalars"

You can plot the chart by taking ...READ MORE

Jan 28, 2019 in Python by Omkar
• 69,210 points
9,169 views
0 votes
1 answer

How to update date automatically after a value change in django?

Hello @kartik, Only change your pub_date if published has ...READ MORE

Jul 3, 2020 in Python by Niroj
• 82,880 points
9,132 views
+1 vote
1 answer

How to validate a field on update in DRF?

Hello @kartik, You can definitely do this using ...READ MORE

Jul 2, 2020 in Python by Niroj
• 82,880 points
9,119 views
0 votes
1 answer

How to return None if Dictionary key is not available

Hello @kartik, You can use dict.get() value = d.get(key) which will ...READ MORE

Apr 30, 2020 in Python by Niroj
• 82,880 points
9,095 views
0 votes
1 answer

How to get the ASCII values of a character in python?

You can get the ASCII value of ...READ MORE

Aug 23, 2020 in Python by Sajetha Selva
9,026 views
0 votes
1 answer

Python error "ImportError: No module named _tkinter, please install the python-tk package"

Use the following command to install tkinter ...READ MORE

Aug 9, 2019 in Python by Chandan
9,020 views
0 votes
1 answer

draw polygon based on user input - turtle python

Try something like this: import turtle # create a ...READ MORE

Jul 6, 2019 in Python by Umer
8,975 views
+1 vote
3 answers

How can I remove duplicate dict in list in Python?

[dict(t) for t in {tuple(d.items()) for d ...READ MORE

Aug 15, 2019 in Python by anonymous

edited Aug 20, 2019 by Kalgi 8,973 views
0 votes
1 answer

how to find files and skip directories in os.listdir

You need to filter out directories; os.listdir() ...READ MORE

Mar 6, 2019 in Python by SDeb
• 13,300 points
8,965 views
0 votes
1 answer

How to Install pip for python 3.7 on Ubuntu 18?

The command you're looking for is: python3.7 -m ...READ MORE

Nov 20, 2020 in Python by Gitika
• 65,910 points
8,942 views
0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

Dec 24, 2018 in Python by Nymeria
• 3,560 points
8,934 views
+1 vote
1 answer

How to install tensorflow using anaconda and python 3.7.1 on windows?

Since I am using python 3.5 so ...READ MORE

Aug 19, 2019 in Python by Arvind
• 3,040 points
8,872 views
0 votes
2 answers

How do you convert a dictionary to a defaultdict?

from collections import defaultdict a = {1: 2, ...READ MORE

Aug 2, 2019 in Python by Mohammad
• 3,230 points
8,870 views
0 votes
1 answer

Is it possible to use variables in SQL statement in Python?

cursor.execute("INSERT INTO table VALUES (%s, %s, %s)", ...READ MORE

Aug 21, 2019 in Python by Neel
• 3,020 points
8,848 views
0 votes
1 answer

Python: XML file to pandas dataframe

Here's an example code: import pandas as pd ...READ MORE

Aug 1, 2019 in Python by Sharon
8,828 views
0 votes
1 answer

How to store a dictionary on a Django Model?

Hello @kartik, If you don't need to query ...READ MORE

Jun 29, 2020 in Python by Niroj
• 82,880 points
8,819 views
0 votes
1 answer

Help fixing the pandas error.

Try this: Uninstall python with admin privileges. Shut down ...READ MORE

Feb 14, 2019 in Python by Saru
8,805 views
0 votes
1 answer

ModuleNotFoundError: No module named 'bs4'

Hi@akhtar, You need to install the bs4 package ...READ MORE

Jun 26, 2020 in Python by MD
• 95,440 points
8,801 views
0 votes
1 answer

How to update user password in Django Rest Framework?

Hello @kartik, Using a modelserializer might be an ...READ MORE

Jul 1, 2020 in Python by Niroj
• 82,880 points
8,759 views
0 votes
1 answer

How do I get user IP address in django?

Hii Kartik, check uwsgi + django source code and pass static param ...READ MORE

Apr 23, 2020 in Python by Niroj
• 82,880 points
8,723 views
0 votes
1 answer

Error: No module named 'django.core.urlresolvers'

Hello @kartik, If you want to import reverse, ...READ MORE

Aug 5, 2020 in Python by Niroj
• 82,880 points
8,700 views
0 votes
1 answer

text = _whitespace_only_re.sub('', text) TypeError: expected string or bytes-like object

This seems like an issue with textwrap ...READ MORE

Feb 13, 2019 in Python by Omkar
• 69,210 points
8,696 views
0 votes
1 answer

How to calculate cosine similarity between two lists using Pythong?

You should try SciPy. It has a bunch ...READ MORE

Dec 18, 2018 in Python by charlie_brown
• 7,720 points
8,692 views
0 votes
1 answer

Error:Python NameError: name 'include' is not defined

Hello @kartik, On the basis of your information provided ...READ MORE

Jul 1, 2020 in Python by Niroj
• 82,880 points
8,668 views
0 votes
4 answers

How to write a single program in python to print different '*' triangles?

If you want to use the same ...READ MORE

Jun 11, 2019 in Python by Likhith
8,644 views
0 votes
1 answer

ModuleNotFoundError: No module named 'torch'

Hi@akhtar, It seems you don't have a torch ...READ MORE

Jun 24, 2020 in Python by MD
• 95,440 points
8,641 views
0 votes
1 answer

Error: Failed building wheel for MySql-Python

Hello @kartik, You need to install the following ...READ MORE

Jul 3, 2020 in Python by Niroj
• 82,880 points
8,632 views
0 votes
1 answer

How to save Numpy array as image in python?

If you have matplotlib, you can do: import ...READ MORE

Nov 16, 2018 in Python by Nymeria
• 3,560 points
8,582 views
0 votes
1 answer

How to get permutations of list or a set in Python?

Permutation is an arrangement of objects in ...READ MORE

Jul 11, 2019 in Python by Neel
• 3,020 points
8,571 views
0 votes
1 answer

Python function to find a list of all keywords

You can use the keyword module for ...READ MORE

Jun 17, 2019 in Python by Ayman
8,547 views
0 votes
1 answer

How change title bar background color in python tkinter?

You cant change colour cause its the ...READ MORE

Jun 10, 2020 in Python by bezlin
8,535 views
0 votes
1 answer

No module named urllib3

It is possible that either urllib3 is ...READ MORE

Jan 24, 2019 in Python by SDeb
• 13,300 points
8,531 views