tagged [python]

Comparing two pandas dataframes for differences

Comparing two pandas dataframes for differences I've got a script updating 5-10 columns worth of data , but sometimes the start csv will be identical to the end csv so instead of writing an identical ...

31 Dec at 14:17

How to delete all instances of a character in a string in python?

How to delete all instances of a character in a string in python? How do I delete all the instances of a character in this string? Here is my code: However, if I run this, this is what happens: ``` >>...

5 Mar at 02:23

How can I send a message to someone with my telegram bot using their Username

How can I send a message to someone with my telegram bot using their Username I am using the telepot python library, I know that you can send a message when you have someone's UserID(Which is a number...

How to display the first few characters of a string in Python?

How to display the first few characters of a string in Python? I just started learning Python but I'm sort of stuck right now. I have `hash.txt` file containing thousands of malware hashes in MD5, Sha...

16 Dec at 02:1

Access multiple elements of list knowing their index

Access multiple elements of list knowing their index I need to choose some elements from the given list, knowing their index. Let say I would like to create a new list, which contains element with ind...

Why can't I install python3.6-dev on Ubuntu16.04

Why can't I install python3.6-dev on Ubuntu16.04 I am trying to install `Python 3.6-dev` with this command: but I'm getting this error: Can anyone help? Why am I getting this error and what is

12 Mar at 22:1

How do I use itertools.groupby()?

How do I use itertools.groupby()? I haven't been able to find an understandable explanation of how to actually use Python's `itertools.groupby()` function. What I'm trying to do is this: - `lxml`- - I...

29 Jul at 19:19

How do I install the yaml package for Python?

How do I install the yaml package for Python? I have a Python program that uses YAML. I attempted to install it on a new server using `pip install yaml` and it returns the following: Ho

18 Jan at 21:3

__init__() missing 1 required positional argument

__init__() missing 1 required positional argument I am trying to learn Python. This is a really simple code. All I am trying to do here is to call a class's constructor. Initialize some variables ther...

4 Mar at 23:17

warning about too many open figures

warning about too many open figures In a script where I create many figures with `fix, ax = plt.subplots(...)`, I get the warning `matplotlib.pyplot.figure` However, I don't understand I get this warn...

30 Jul at 11:31

Why I get 'list' object has no attribute 'items'?

Why I get 'list' object has no attribute 'items'? Using Python 2.7, I have this list: I'd like to extract values out of it. i.e. `[15, 9, 16]` So I tried: But instead, I get this error: ``` Traceback ...

27 Nov at 03:34

How to dynamically load a Python class

How to dynamically load a Python class Given a string of a Python class, e.g. `my_package.my_module.MyClass`, what is the best possible way to load it? In other words I am looking for a equivalent `Cl...

29 Sep at 21:27

Working with TIFFs (import, export) in Python using numpy

Working with TIFFs (import, export) in Python using numpy I need a python method to open and import TIFF images into numpy arrays so I can analyze and modify the pixel data and then save them as TIFFs...

How to convert a hex string to hex number

How to convert a hex string to hex number I want to convert a hex string (ex: `0xAD4`) to hex number, then to add `0x200` to that number and again want to print that number in form of `0x` as a string...

19 Feb at 12:55

How to use Python requests to fake a browser visit a.k.a and generate User Agent?

How to use Python requests to fake a browser visit a.k.a and generate User Agent? I want to get the content from [this](http://www.ichangtou.com/#company:data_000008.html) website. If I use a browser ...

How to join entries in a set into one string?

How to join entries in a set into one string? Basically, I am trying to join together the entries in a set in order to output one string. I am trying to use syntax similar to the join function for lis...

30 Jan at 13:27

How to check if a variable is an integer or a string?

How to check if a variable is an integer or a string? I have an application that has a couple of commands. When you type a certain command, you have to type in additional info about something/someone....

10 May at 18:6

Connection Timeout with Elasticsearch

Connection Timeout with Elasticsearch This simples code is returning t

18 Jun at 16:50

How do I convert a PIL Image into a NumPy array?

How do I convert a PIL Image into a NumPy array? How do I convert a PIL `Image` back and forth to a NumPy array so that I can do faster pixel-wise transformations than PIL's `PixelAccess` allows? I ca...

Remove list from list in Python

Remove list from list in Python > [Get difference from two lists in Python](https://stackoverflow.com/questions/5305164/get-difference-from-2-lists-python) What is a simplified way of doing this? I ...

23 May at 12:34

"for line in..." results in UnicodeDecodeError: 'utf-8' codec can't decode byte

"for line in..." results in UnicodeDecodeError: 'utf-8' codec can't decode byte Here is my code, Whenever I run this code it gives the following error: > UnicodeDecodeError: 'utf-8' codec can't decode...

30 Jan at 16:27

Which is the preferred way to concatenate a string in Python?

Which is the preferred way to concatenate a string in Python? Since Python's `string` can't be changed, I was wondering how to concatenate a string more efficiently? I can write like it: or like this:...

How to get the index with the key in a dictionary?

How to get the index with the key in a dictionary? I have the key of a python dictionary and I want to get the corresponding index in the dictionary. Suppose I have the following dictionary, Is there ...

How to write a Python module/package?

How to write a Python module/package? I've been making Python scripts for simple tasks at work and never really bothered packaging them for others to use. Now I have been assigned to make a Python wra...

24 Mar at 12:29

threading.Timer - repeat function every 'n' seconds

threading.Timer - repeat function every 'n' seconds I want to fire off a function every 0.5 seconds and be able to start and stop and reset the timer. I'm not too knowledgeable of how Python threads w...

Python requests module sends JSON string instead of x-www-form-urlencoded param string

Python requests module sends JSON string instead of x-www-form-urlencoded param string I was under the impression that POSTSs using x-www-form-urlencoded specifications should send a URL encoded param...

28 Oct at 18:25

Saving response from Requests to file

Saving response from Requests to file I'm using [Requests](http://docs.python-requests.org/en/latest/api/) to upload a PDF to an API. It is stored as "response" below. I'm trying to write that out to ...

20 Feb at 14:46

How to download image using requests

How to download image using requests I'm trying to download and save an image from the web using python's `requests` module. Here is the (working) code I used: Here is the new (non-working) code using...

30 Oct at 11:14

Python DNS module import error

Python DNS module import error I have been using python dns module.I was trying to use it on a new Linux installation but the module is not getting loaded. I have tried to clean up and install but the...

8 Feb at 20:36

Python: how to capture image from webcam on click using OpenCV

Python: how to capture image from webcam on click using OpenCV I want to capture and save a number of images from my webcam using OpenCV. This is my code currently: The problem with this is that I do ...

4 Jan at 09:53

How do I change the string representation of a Python class?

How do I change the string representation of a Python class? In Java, I can override the `toString()` method of my class. Then Java's print function prints the string representation of the object defi...

6 Nov at 10:4

How can I force division to be floating point? Division keeps rounding down to 0?

How can I force division to be floating point? Division keeps rounding down to 0? I have two integer values `a` and `b`, but I need their ratio in floating point. I know that `a

TypeError: Missing 1 required positional argument: 'self'

TypeError: Missing 1 required positional argument: 'self' I have some code like: But I get an error like: ``` Traceback (most recent call last): File "C:\Users\Dom\Desktop\test\test.py", line 7, in ...

input() error - NameError: name '...' is not defined

input() error - NameError: name '...' is not defined I am getting an error when I try to run this simple script: Let's say I type in "dude", the error I am getting is: ``` line 1, in input_variable ...

23 Nov at 05:44

Find column whose name contains a specific string

Find column whose name contains a specific string I have a dataframe with column names, and I want to find the one that contains a certain string, but does not exactly match it. I'm searching for `'sp...

Using python Requests with javascript pages

Using python Requests with javascript pages I am trying to use the Requests framework with python ([http://docs.python-requests.org/en/latest/](http://docs.python-requests.org/en/latest/)) but the pag...

15 Oct at 22:31

Asyncio.gather vs asyncio.wait

Asyncio.gather vs asyncio.wait [asyncio.gather](https://docs.python.org/3/library/asyncio-task.html#asyncio.gather) and [asyncio.wait](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait)...

Not able to install Python packages [SSL: TLSV1_ALERT_PROTOCOL_VERSION]

Not able to install Python packages [SSL: TLSV1_ALERT_PROTOCOL_VERSION] I am trying to install a Python library using `pip`, getting an SSL error: ``` ~/projects/base  pre-master± pip install xdict C...

21 May at 10:40

Convert png to jpeg using Pillow

Convert png to jpeg using Pillow I am trying to convert png to jpeg using pillow. I've tried several scrips without success. These 2 seemed to work on small png images like this one. [](https://i.stac...

How to uninstall Python 2.7 on a Mac OS X 10.6.4?

How to uninstall Python 2.7 on a Mac OS X 10.6.4? I want to completely remove Python 2.7 from my Mac OS X 10.6.4. I managed to remove the entry from the `PATH` variable by reverting my `.bash_profile`...

The right way to limit maximum number of threads running at once?

The right way to limit maximum number of threads running at once? I'd like to create a program that runs multiple light threads, but limits itself to a constant, predefined number of concurrent runnin...

NLTK python error: "TypeError: 'dict_keys' object is not subscriptable"

NLTK python error: "TypeError: 'dict_keys' object is not subscriptable" I am following instructions for a class homework assignment and I am supposed to look up the top 200 most frequently used words ...

20 Aug at 08:33

How to create a DataFrame of random integers with Pandas?

How to create a DataFrame of random integers with Pandas? I know that if I use [randn](https://numpy.org/doc/stable/reference/random/generated/numpy.random.randn.html), the following code gives me wha...

Safest way to convert float to integer in python?

Safest way to convert float to integer in python? Python's math module contain handy functions like `floor` & `ceil`. These functions take a floating point number and return the nearest integer below ...

5 Aug at 18:21

How can I install Python's pip3 on my Mac?

How can I install Python's pip3 on my Mac? I'm trying to install pip3, but I'm not having any luck. Also, I tried `sudo install` and it did not work. How could I install pip3 on my Mac? ``` sudo easy_...

6 Dec at 07:9

Understanding __get__ and __set__ and Python descriptors

Understanding __get__ and __set__ and Python descriptors I am to understand what Python's descriptors are and what they are useful for. I understand how they work, but here are my doubts. Consider the...

12 Jun at 01:12

No module named setuptools

No module named setuptools I want to install setup file of twilio. When I install it through given command it is given me an error: > No module named setuptools. Could you please let me know what shou...

22 Jul at 09:1

How to choose bins in matplotlib histogram

How to choose bins in matplotlib histogram Can someone explain to me what "bins" in histogram are (the [matplotlib hist](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist) function)? An...

3 May at 02:24

Removing numbers from string

Removing numbers from string How can I remove digits from a string?

10 Oct at 04:16

What is the correct syntax for 'else if'?

What is the correct syntax for 'else if'? I'm a new Python programmer who is making the leap from 2.6.4 to 3.1.1. Everything has gone fine until I tried to use the 'else if' statement. The interpreter...

5 Mar at 15:3