Align columns in a text file

I have a plain text file that contains user login data: dtrapani HCPD-EPD-3687 Mon 05/13/2013 9:47:01.72 dlibby HCPD-COS-4611 Mon 05/13/2013 9:49:34.55 lmurdoch HCPD-SDDEB-3736 Mon ...

How to set Python's default version to 3.x on OS X?

I'm running Mountain Lion and the basic default Python version is 2.7. I downloaded Python 3.3 and want to set it as default. Currently: $ python version 2.7.5 $ python3.3 version...

check for file existence in Python 3

I would like to know how I could check to see if a file exist based on user input and if it does not, then i would like to create one. so I would have something like: file_name = input('what is...

Count items greater than a value in pandas groupby

I have the Yelp dataset and I want to count all reviews which have greater than 3 stars. I get the count of reviews by doing this: reviews.groupby('business_id')['stars'].count() Now I want to...

DataConversionWarning: A column-vector y was passed when a 1d array was expected

I keep having an error running this part of my code: scores = cross_val_score(XGB_Clf, X_resampled, y_resampled, cv=kf) The error is : DataConversionWarning: A column-vector y was passed when a...

Modify a list by deleting the first element

I don't understand what I am doing wrong. The output I receive from this code is not right. Modify short_names by deleting the first element and changing the last element to Joe. Sample output...

Changing fonts in matplotlib

So I've tried pretty much everything I could find on stackoverflow (and anywhere else google would lead me) ; and I just can't change the god damn font ! Here comes the non-exhaustive list of what...

best way to use ruamel.yaml to dump to string NOT to stream

In the past, I did something like some_fancy_printing_loggin_func(yaml.dump(...), ...), using the backward-compatible part of ruamel.yaml, but I want to convert my code to use the latest API so...

Search and replace dots and commas in pandas dataframe

This is my DataFrame: d = {'col1': ['sku 1.1', 'sku 1.2', 'sku 1.3'], 'col2': ['9.876.543,21', 654, '321,01']} df = pd.DataFrame(data=d) df col1 col2 0 sku 1.1 ...

Getting links of Youtube search result

I am trying to get links of videos that appear in search result for a particular query on YouTube. I am using BeautifulSoup and requests library of Python and here is what I did: from bs4 import...

Logging and raising an exception

I'd like to keep a solid logging system going, but it's also necessary to raise exceptions. This code accomplishes what I'm going for, but it looks clunky and not very Pythonic. What's a better...

Python dataclass from a nested dict

The standard library in 3.7 can recursively convert a dataclass into a dict (example from the docs): from dataclasses import dataclass, asdict from typing import List @dataclass class Point: ...

How can I get the href of anchor tag using Beautiful Soup?

I am trying to get the href of anchor tag of the very first video search on YouTube using Beautiful Soup. I am searching it by using the "a" and class_="yt-simple-endpoint style-scope...

TypeError: decrypt() cannot be called after encrypt()

I am writing a simple code of AES encryption. I got stuck at a part where it says decrypt() cannot be called after encrypt(). I searched through the internet to find the solution, but unable to do...

The reason cause different location of python packages

I am new to Linux system and don't have background about operating system. I have some issues about importing numpy,but I worked it out. But still have some questions in my mind. I know that I can...

Jinja2 template in Python 3 renders bytes with "b" prefix and quotes

I'm converting a flask app from python 2 to 3, Jinja2 now renders bytes with trailing b and single quotes, e.g. b'a123' while I need them rendered as a123. This happens with all urlsafe strings...

how to use iterator in while loop statement in python

Is it possible to use a generator or iterator in a while loop in Python? For example, something like: i = iter(range(10)) while next(i): # your code The point of this would be to build...

Converting QPixmap to grayscale

I'm trying to convert QPixmap image to grayscale. However, I got an error for all tried solution. The first try: def convertCv2ToQimage(self, cv2image): height, width = cv2image.shape ...

Lag when win.blit() background pygame

I'm having trouble with the framerate in my game. I've set it to 60 but it only goes to ~25fps. This was not an issue before displaying the background (was fine with only win.fill(WHITE)). Here is...

Delete all vowels from a string using a list-comprehension

I'm trying to solve a challenge on Codewars. Trolls are attacking your comment section! A common way to deal with this situation is to remove all of the vowels from the trolls' comments,...

How to decode and visualize DICOM curve data in Python 3?

I am trying to visualize a DICOM file with Python 3 and pyDicom which should contain a black 100x100 image with some curves drawn in it. The pixel data is extracted from header (7fe0,0010) and...

Google translate api return non utf8 charactere

Resolve See in the end of this post for the solution Good evening. Im trying to play with the google translate v3 api. And I arrive on a mystical encoding issue. I do this : def...

Generalize hourglass movement in 2D Array - DS in Python

While working through this HackerRank challenge to prepare for interviews, stumbled across a blocker. Basically want to create a function hourglassSum that should return an integer (the maximum...

Anaconda and upgrading to new M1 Mac

Background I've just got a new M1 mac mini dev machine, and migrated from my old x86 mac using apple's migration assistant. Doing that also copied over all my conda environments to the new machine...

How to correctly pass the generator to the function parameters of ThreadPoolExecutor Executor.map()?

In the following program, I have two questions I want to ask. The first question is, why do I need to traverse the generator before calling the function when I use the thread pool to pass the...

tensorflow audio recognition error 'Header mismatch: Expected RIFF but found '

I'm new to tf and I'm trying to read some audio for genre recognition. I'm following a guide from tf's website regarding this subject, but I keep running into 2 errors. The first is with this...

Paramiko SSH command execution failing with `ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS`

Executing a command on remote machine using SSH is failing with the below error: Traceback (most recent call last): File "ssh.py", line 4, in <module> ssh_client.connect(hostname='10.x.x.x',...

Binance Api Python setup

I created a Bot to trade BTC with Binance and am currently trying to set my Raspberry Pi 3 B+ up. With every pip install python-binance I get Using cached backports.zoneinfo-0.2.1.tar.gz (74...

GeneratorDatasetOp:Dataset will not be optimized because the dataset does not implement the AsGraphDefInternal() method needed to apply optimizations

I have created a tf record and used it to train my model. During the training process, Whenever I am calling my data to perform the evaluation I am always getting the message Input of...

Maximum path sum of 2 lists

My question is about this kata on Codewars. The function takes two sorted lists with distinct elements as arguments. These lists might or might not have common items. The task is find the maximum...