Questions tagged [python-3.x]

58545 questions
1

votes
2

answer
377

Views

How to split a string with regexp without keeping capture groups?

I want to split text with a regular expression with backreference in Python. rexp = re.compile(r'([`]{1,})ABC\1') rexp.split('blahblah``ABC``blahblah') I got ['blahblah', '``', 'blahblah'] but expected ['blahblah', 'blahblah']. How can I split string without keeping capture groups?
Zz Tux
1

votes
1

answer
37

Views

How to combine strings in one DataFrame

I am processing inbound user data. I receive DataFrame h that is supposed to contain all float but has some strings: >>> h = pd.DataFrame(np.random.rand(3, 2), columns=['a', 'b']) >>> h.loc[0, 'a'] = 'bad' >>> h.loc[1, 'b'] = 'robot' >>> h a b 0 bad 0.747314 1 0.921919 ro...
Jason Strimpel
1

votes
3

answer
28

Views

Running a external program using Python

I want to launch a external program like notepad.exe using python. I want to have a script that just runs Notepad.exe.
Calvin
0

votes
0

answer
22

Views

Applying a function to every row in a dataframe in Python

I have a dataframe of 2 rows and D P h O Q SD LT 80 27 0.37 50 2 3 1.51 50 10 0.25 5 10 12 0.03 I have a function that I want to apply to every row, but I get the same result for every row I have tried to iter over rows with the following code: from scipy.stats im...
0

votes
0

answer
16

Views

Creating a Python module with its dependencies self contained

When creating a Python module, you can specify dependencies of your module by using the install_requires List. Lets look at this basic example. setup(name='some_module', version='0.0.1', packages=find_packages(), install_requires=[ 'requests==2.21.0' ]) I package my module python3 setup.py sdist and...
chasez0r
0

votes
0

answer
5

Views

How to handle big textual data to create WordCloud?

I have a huge textual data that I need to create its word cloud. I am using a Python library named word_cloud in order to create the word cloud which is quite configurable. The problem is that my textual data is really huge, so a high-end computer is not able to complete the task even for long hours...
talha06
0

votes
0

answer
10

Views

Subset-AVG - Finding a subset of List Which Matches Known Rational Number

I've asked this on math overflow and used comments to clarify/overstate my question. I hope it has the intended effect and doesn't come off as jarring. I'm attempting to find what subset of numbers reach a known average. I have a list of known values, negative and possible decimals. They look somet...
Raymond Johnson
0

votes
0

answer
2

Views

opencv Python PPF detector crash

I´ve noticed that the PPF3DDetector is now available in Python too. So I´ve tried to run this piece of sample code: ppf_load_match, but Python keeps chrashing when 'matching'. It takes a while to train the model, but you can increase the first argument of 'cv.ppf_match_3d_PPF3DDetector' to run it...
ZZM
1

votes
3

answer
498

Views

Get features from sklearn feature union

I have a feature union which uses some custom transformers to select text and parts of a dataframe. I would like to understand which features it's using. The pipeline selects and transforms columns and then selects k best. I'm able to pull out the features from k best using the following code: mask...
avocet
1

votes
1

answer
192

Views

how to extract href from <a> element using lxml cssselctor?

def extract_page_data(html): tree = lxml.html.fromstring(html) item_sel = CSSSelector('.my-item') text_sel = CSSSelector('.my-text-content') time_sel = CSSSelector('.time') author_sel = CSSSelector('.author-text') a_tag = CSSSelector('.a') for item in item_sel(tree): yield {'href': a_tag(item)[0].te...
elrich bachman
1

votes
2

answer
776

Views

How to read two different files in Python by sys.stdin

I want to read two different files from sys.stdin, I can read and write file but there is no separation from first and second file. When I run below code on cmd win 10 and python 3.6: D:\digit>cat s.csv s2.csv Result is: 1 2 3 4 5 1 2 3 4 5 6 7 I can print both files. My python code is: import sys...
Mahsa Hassankashi
1

votes
1

answer
2.4k

Views

What does '%% time' mean in python-3?

What does %%time mean in python? I am using python 3 and have some source code containing %%time Does this call the time module? or does it have another function?
JZF
1

votes
1

answer
219

Views

bordermode attribute in place() method of tkinter python

What is the difference between bordermode = OUTSIDE and bordermode = INSIDE attribute in place() method of tkinter in python?
Nehal Birla
1

votes
1

answer
2.7k

Views

Python: Moving files to folder based on filenames

I have a folder with 10 images that I wish to move into a new folder based on it's current filenames. I've successfully been able to move every images in the folder into a new folder, and as of now I've been successful at moving each image filename to its own folder but I've yet to figure out how to...
ZenB883
1

votes
2

answer
291

Views

Python default/implicit string encodings

When, where and how does Python implicitly apply encodings to strings or does implicit transcodings (conversions)? And what those 'default' (i.e. implied) encodings are? For example, what are the encodings: of string literals? s = 'Byte string with national characters' us = u'Unicode string with nat...
ivan_pozdeev
1

votes
2

answer
142

Views

Why is it best practice to include the dependencies' dependencies in requirements.txt?

I appreciate that in many circumstances it is important to explicitly state what dependency versions we are working with and that this thus applies to the nested dependencies as well. However, it becomes very messy when we decide to remove a dependency and need to use something like pideptree to fi...
Ludo
1

votes
1

answer
838

Views

how save photo in telegram python bot?

i want to write a telegram bot that save photos . this is my code , but its not working. and i don't know what is my problem? def image_handler(bot, update): file = bot.getFile(update.message.photo.file_id) print ('file_id: ' + str(update.message.photo.file_id)) file.download('image.jpg') updater.d...
Ali
1

votes
1

answer
548

Views

TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a' - even after casting

I get the following error when I try to run the following program TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'. I figured it says that _x is of type int32, but I already cast it using tf.cast import tensorflow as tf import numpy as np x = ([[3,...
ab123
1

votes
1

answer
198

Views

How to mark a verb in a sentence, using spaCy? Python

I want to mark verbs in sentences by adding an 'X' at the end of the verb word, like this verbX. SpaCy assigns tags to sentence elements that Python does not index separately. For example, spaCy sees a bracket '(' or full stop behind a word '.' as a separate position, whereas Python does not. As a r...
twhale
1

votes
1

answer
237

Views

In PyTest how to config CaptureManager plugin error 'CaptureManager' object has no attribute 'suspendcapture'

I have the following function called from a pytest. def ask_user_input(msg=''): ''' Asks user to check something manually and answer a question ''' notification = '\n\n???\tANSWER NEEDED\t???\n\n{}'.format(msg) # suspend input capture by py.test so user input can be recorded here capture_manager = p...
MrKnotts
1

votes
1

answer
206

Views

How to fix blurry text in WxPython controls on Windows?

We have a Python-based application written with WxPython 4 that we build for multiple operating systems, including Windows. In Windows 10, at least in my environment (inside a VM on a high resolution monitor), the text elements in the interface are blurry: I can improve the situation somewhat by set...
mhucka
1

votes
1

answer
1.6k

Views

Problems getting fastpython protobuf support

I see that there is supposed to be support for creating python wrappers to the C++ generated protobuf readers. From http://yz.mit.edu/wp/fast-native-c-protocol-buffers-from-python/ I find a simple way to turn on support by setting the environment variable: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp...
Techniquab
0

votes
1

answer
11

Views

Pandas BuildPaths Efficiently

I have a Pandas dataframe like below, which has two arbitrary customers with 2 months' data(there are more months) and ATL_Flag which are marketing channels(there are more of them too): |App_Flag|ATL_Flag|Cust_No|month1|month2 | 0 | TV | 1 | 1 | 0 | 0 | FB | 1 | 0 | 0...
Ahsan
-2

votes
1

answer
16

Views

How to pass Boolean value (True/False)to if statement with pyautogui?

I am building a robot that plays web game automatically with pyautogui. I use pyautogui.pixelMatchesColor() function to detect the color on pixels, and it returns the correct True and False value to me. But I don't know how to pass Boolean value to if statement. If t01 = True, I want to move my mous...
林侑萱
1

votes
2

answer
276

Views

using duplicates values from one column to remove entire row in pandas dataframe

I have the data in the csv file uploaded in the following link Clikc here for the data In this file i have the following columns Team Group Model SimStage Points GpWinner GpRunnerup 3rd 4th There will be duplicates in the columns Team. Another columns is SimStage. Simstage is having a s...
Zephyr
1

votes
3

answer
231

Views

docker build is failing when snowflake dependency is included in the pip requirements

I am trying to build docker image out of my python application. But when I am adding 'snowflake-connector-python' to the pip requirements.txt file the docker build is failing. requirements.txt:- boto3 pycryptodome snowflake-connector-python Dockerfile:- FROM python:alpine3.6 RUN python --version CO...
dks551
1

votes
1

answer
90

Views

How to save openCV classifier?

I want to save a classifier that has been trained on multiple images to avoid the time it takes to re-train it every time I run the program. For sklearn's classifiers I was able to simply pickle them, using pickle.load but when I try doing the same I get following error: TypeError: can't pickle cv2...
Ach113
1

votes
1

answer
150

Views

Python modifying dict entries in-place during iteration

I know that in the general case, it’s unsafe to mutate a dict while iterating over it: d = {1: 2, 3: 4} for k in d.keys(): d[k + 1] = d[k] + 1 This yields a RuntimeError as expected. However, while reading the documentation for dict, I found the following (emphasis mine): Iterating views while add...
Andrew Sun
1

votes
2

answer
48

Views

Having trouble with Entry variables in tkinter Python

from tkinter import * root = Tk() root.geometry('800x650') e = Entry(root, width=3, font=('Verdana', 30), justify='right') a = b = c = e a.place(relx=0.2, rely=0.5, anchor=CENTER) b.place(relx=0.44, rely=0.5, anchor=CENTER) c.place(relx=0.65, rely=0.5, anchor=CENTER) root.mainloop() Why can't I see...
Chris
1

votes
4

answer
154

Views

What is difference between parenthesis and bracket in Numpy?

Could somebody explain the difference between () and [] operations in Numpy? For example, I have run the following codes: import numpy as np x1 = np.array(([2, 9], [1, 5], [3, 6]), dtype=float) print(x1) print(type(x1)) x2 = np.array([[2, 9], [1, 5], [3, 6]], dtype=float) print(x2) print(type(x2)) y...
user10523691
1

votes
1

answer
59

Views

Plot multiple values with matplotlib without loop

I have two nested lists with the values for the x-axis and y-axis that I want to plot in the same figure. Whith a for loop to iterate through the values produces the expected plot, but for large lists is relatively slow. So I was looking for the same functionality but without the loop, which I thoug...
PedroA
1

votes
1

answer
1.1k

Views

django.core.exceptions.SuspiciousFileOperation: The joined path is located outside of the base path component

This worked fine everytime used to do django websites but this time it is giving me an error. Settings.py STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'portfolio/static/') ] STATIC_ROOT = os.path.join(BASE_DIR , 'static') STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL...
Kiran Chavan
1

votes
1

answer
412

Views

pip search finds tensorflow, but pip install does not

I am trying to build a Django app that would use Keras models to make recommendations. Right now I'm trying to use one custom container that would hold both Django and Keras. Here's the Dockerfile I've written. # myproject/docker/app/Dockerfile FROM python:3.7-alpine # I've tried 3.5, 3.6 and 3.7 R...
julka
2

votes
4

answer
50

Views

Is there an equivalent to get() in python? [duplicate]

This question already has an answer here: How do I create a variable number of variables? 16 answers I have a sequence of messages in json and they include a field called part, which is an integer from 0 to 2. I have three message queues and the value of part determines which queue I send the messa...
tadon11Aaa
0

votes
1

answer
17

Views

can not using 'cd' command in Python console

I want to change directory using 'cd' command in PyCharm's python console. It works all the time until I bought a new PC. Environment is Python 3.7; Pycharm 2019.1.1. I google it and some guys told me to use os.chdir() but I want to use 'cd' because it is some kind easy to use. The error report is:...
xxyao
0

votes
0

answer
27

Views

How to count the number of instances between two dates/times

Noobie here, so please bear with me. I'll try to make this as concise as possible. I have two dataframes: df2: Consists of unique visit number for each person, time the person arrived to our store, time the person departure departed from our store df1: Is a subset of visit numbers from df2 (as well...
gwf215
0

votes
1

answer
20

Views

pandas remove parentheses and the inside stuff in a string keep one space inside it

I would like to remove parentheses and the inside stuff in a string in pandas framework but I want to keep one space if the '()' inside the string. e.g. (.)y(...)rfer --> y rfer a(...)ewq() --> a ewq my code: df['a_id'].apply(lambda x: x.replace('\(.*\)', ' ')) does not work. thanks
user3448011
0

votes
0

answer
15

Views

How can I create an L2TP VPN connection in Python?

How can I establish a python-based VPN connection? I want to create an L2TP VPN.
Emad Firooze
0

votes
1

answer
15

Views

Why my piglatin translator code is giving unexpected output?

I have built a fun project named piglatin translator. It works on two principles. 1. If words in the sentence start with vowel then add 'yay' at the last of the word. 2. If the word starts with consonant. Find vowel in the word transfer the constant cluster at the end and add 'ay' # Ask for the sent...
Shihab
1

votes
1

answer
11

Views

In urllib3, HTTP request hangs … but doesn't in curl

(Thanks for taking a look at this!) I'm trying to use python3 and simple urllib3 http.request to read HTML from https://login.morganstanleyclientserv.com. It seems like the server is resetting the connection, and eventually urllib3's retries give up. Is there a TLS negotiation issue here? If so, ho...
bdemchak

View additional questions