qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
60,548,289
I don't know why I am getting this error. Below is the code I am using. **settings.py** ``` TEMPLATE_DIRS = (os.path.join(os.path.dirname(BASE_DIR), "mysite", "static", "templates"),) ``` **urls.py** ``` from django.urls import path from django.conf.urls import include, url from django.contrib.auth import views as...
2020/03/05
[ "https://Stackoverflow.com/questions/60548289", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5227269/" ]
**second Solution** - this is because you have not bind the function and calling it in the click event Please refer [Handling events](https://reactjs.org/docs/handling-events.html) So add this line inside the constructor ``` this.resetTimer = this.resetTimer.bind(); ``` I hope this solves your problem :)
You have to bind the method call with the event as suggested by other users If you don't bind the method, It will be always be called with the re-render First approach Inside constructor `this.methodName = this.bind.methodName(this);` Inside render() ``` render(){ return( <button onClick={this.methodName}></button>...
64,965,247
I was developing a bot on discord, and I want to log when user roles changes. I tried the code below and that was just starting. ```py TOKEN = "" client = discord.Client() @client.event async def on_ready(): print(f'{client.user} has connected to Discord!') @client.event async def on_message(message): print...
2020/11/23
[ "https://Stackoverflow.com/questions/64965247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14041512/" ]
Your intents should be enabled both on the portal and the code itself. Here is how you do it in the code. ```py intents = discord.Intents().all() client = discord.Client(intents=intents) ``` And according to the [docs of on\_memebr\_update](https://discordpy.readthedocs.io/en/latest/api.html#discord.on_member_updat...
You should activate that from your code like: ```py intents = discord.Intents.default() intents.members = True intents.presences = True client= discord.Client(intents=intents) ``` [reference for more information](https://discordpy.readthedocs.io/en/latest/intents.html)
61,296,763
I have trained a CNN in Matlab 2019b that classifies images between three classes. When this CNN was tested in Matlab it was functioning fine and only took 10-15 seconds to classify an image. I used the exportONNXNetwork function in Maltab so that I can implement my CNN in Tensorflow. This is the code I am using to use...
2020/04/18
[ "https://Stackoverflow.com/questions/61296763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Maybe you could try to understand what part of the code takes a long time this way: ``` import onnx from onnx_tf.backend import prepare import numpy as np from PIL import Image import datetime now = datetime.datetime.now() onnx_model = onnx.load('trainednet.onnx') tf_rep = prepare(onnx_model) filepath = 'filepath.p...
You should consider some points while working on TensorFlow with Python. A GPU will be better for work as it fastens the whole processing. For that, you have to install CUDA support. Apart from this, the compiler also sometimes matters. I can tell VSCode is better than Spyder from my experience. I hope it helps.
61,296,763
I have trained a CNN in Matlab 2019b that classifies images between three classes. When this CNN was tested in Matlab it was functioning fine and only took 10-15 seconds to classify an image. I used the exportONNXNetwork function in Maltab so that I can implement my CNN in Tensorflow. This is the code I am using to use...
2020/04/18
[ "https://Stackoverflow.com/questions/61296763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Maybe you could try to understand what part of the code takes a long time this way: ``` import onnx from onnx_tf.backend import prepare import numpy as np from PIL import Image import datetime now = datetime.datetime.now() onnx_model = onnx.load('trainednet.onnx') tf_rep = prepare(onnx_model) filepath = 'filepath.p...
Since the command prompt states that your program takes a long time to perform constant folding, it might be worthwhile to turn this off. [Based on this documentation](https://www.tensorflow.org/guide/graph_optimization), you could try running: ``` import numpy as np import timeit import traceback import contextlib im...
61,296,763
I have trained a CNN in Matlab 2019b that classifies images between three classes. When this CNN was tested in Matlab it was functioning fine and only took 10-15 seconds to classify an image. I used the exportONNXNetwork function in Maltab so that I can implement my CNN in Tensorflow. This is the code I am using to use...
2020/04/18
[ "https://Stackoverflow.com/questions/61296763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In this case, it appears that the [Grapper optimization suite](https://web.stanford.edu/class/cs245/slides/TFGraphOptimizationsStanford.pdf) has encountered some kind of infinite loop or memory leak. I would recommend filing an issue against the [Github repo](https://github.com/tensorflow/tensorflow/tree/master/tensorf...
You should consider some points while working on TensorFlow with Python. A GPU will be better for work as it fastens the whole processing. For that, you have to install CUDA support. Apart from this, the compiler also sometimes matters. I can tell VSCode is better than Spyder from my experience. I hope it helps.
61,296,763
I have trained a CNN in Matlab 2019b that classifies images between three classes. When this CNN was tested in Matlab it was functioning fine and only took 10-15 seconds to classify an image. I used the exportONNXNetwork function in Maltab so that I can implement my CNN in Tensorflow. This is the code I am using to use...
2020/04/18
[ "https://Stackoverflow.com/questions/61296763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In this case, it appears that the [Grapper optimization suite](https://web.stanford.edu/class/cs245/slides/TFGraphOptimizationsStanford.pdf) has encountered some kind of infinite loop or memory leak. I would recommend filing an issue against the [Github repo](https://github.com/tensorflow/tensorflow/tree/master/tensorf...
Since the command prompt states that your program takes a long time to perform constant folding, it might be worthwhile to turn this off. [Based on this documentation](https://www.tensorflow.org/guide/graph_optimization), you could try running: ``` import numpy as np import timeit import traceback import contextlib im...
50,315,645
I have a simple script which is using [signalr-client-py](https://github.com/TargetProcess/signalr-client-py) as an external module. ``` from requests import Session from signalr import Connection import threading ``` When I try to run my script using the `sudo python myScriptName.py` I get an error: ``` Traceback...
2018/05/13
[ "https://Stackoverflow.com/questions/50315645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128702/" ]
By default sudo runs commands in different environment. You can ask sudo to preserve environment with `-E` switch. ``` sudo -E python myScriptName.py ``` It comes with it's own security risks. So be careful
You need to check where signalr is installed. sudo runs the program in the environment available to root and if signalr is not installed globally it won't be picked up. Try 'sudo pip freeze' to see what is available in the root environment.
50,315,645
I have a simple script which is using [signalr-client-py](https://github.com/TargetProcess/signalr-client-py) as an external module. ``` from requests import Session from signalr import Connection import threading ``` When I try to run my script using the `sudo python myScriptName.py` I get an error: ``` Traceback...
2018/05/13
[ "https://Stackoverflow.com/questions/50315645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128702/" ]
You need to check where signalr is installed. sudo runs the program in the environment available to root and if signalr is not installed globally it won't be picked up. Try 'sudo pip freeze' to see what is available in the root environment.
Another easy solution can be installing required packages via `sudo` -even they are installed before normally- instead of trying to match the paths: `sudo pip3 install <your-required-package-name>` After that you can execute the scripts via `sudo`.
50,315,645
I have a simple script which is using [signalr-client-py](https://github.com/TargetProcess/signalr-client-py) as an external module. ``` from requests import Session from signalr import Connection import threading ``` When I try to run my script using the `sudo python myScriptName.py` I get an error: ``` Traceback...
2018/05/13
[ "https://Stackoverflow.com/questions/50315645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128702/" ]
By default sudo runs commands in different environment. You can ask sudo to preserve environment with `-E` switch. ``` sudo -E python myScriptName.py ``` It comes with it's own security risks. So be careful
Another easy solution can be installing required packages via `sudo` -even they are installed before normally- instead of trying to match the paths: `sudo pip3 install <your-required-package-name>` After that you can execute the scripts via `sudo`.
16,170,268
I have written a python27 module and installed it using `python setup.py install`. Part of that module has a script which I put in my bin folder within the module before I installed it. I think the module has installed properly and works (has been added to site-packages and scripts). I have built a simple script "test...
2013/04/23
[ "https://Stackoverflow.com/questions/16170268", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2270903/" ]
Are you using `distutils` or `setuptools`? I tested right now, and if it's distutils, it's enough to have `scripts=['bin/script_name']` in your `setup()` call If instead you're using setuptools you can avoid to have a script inside bin/ altogether and define your entry point by adding `entry_points={'console_scrip...
Please check your installed module for using condition to checking state of global variable `__name__`. I mean: ``` if __name__ == "__main__": ``` Global variable `__name__` changing to "`__main__`" string in case, then you starting script manually from command line (e.g. python sample.py). If you using this conditi...
36,212,431
I want to using python to open two files at the same time, read one line from each of them then do some operations. Then read the next line from each of then and do some operation,then the next next line...I want to know how can I do this. It seems that `for` loop cannot do this job.
2016/03/25
[ "https://Stackoverflow.com/questions/36212431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5362936/" ]
``` file1 = open("some_file") file2 = open("other_file") for some_line,other_line in zip(file1,file2): #do something silly file1.close() file2.close() ``` note that `itertools.izip` may be prefered if you dont want to store the whole file in memory ... also note that this will finish when the end of either fil...
Why not read each file into a list each element in the list holds 1 line. Once you have both files loaded to your lists you can work line by line (index by index) through your list doing whatever comparisons/operations you require.
36,212,431
I want to using python to open two files at the same time, read one line from each of them then do some operations. Then read the next line from each of then and do some operation,then the next next line...I want to know how can I do this. It seems that `for` loop cannot do this job.
2016/03/25
[ "https://Stackoverflow.com/questions/36212431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5362936/" ]
``` file1 = open("some_file") file2 = open("other_file") for some_line,other_line in zip(file1,file2): #do something silly file1.close() file2.close() ``` note that `itertools.izip` may be prefered if you dont want to store the whole file in memory ... also note that this will finish when the end of either fil...
you can put inside a loop like that: ``` for x in range(0, n): read onde line read the other line ``` try it
36,212,431
I want to using python to open two files at the same time, read one line from each of them then do some operations. Then read the next line from each of then and do some operation,then the next next line...I want to know how can I do this. It seems that `for` loop cannot do this job.
2016/03/25
[ "https://Stackoverflow.com/questions/36212431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5362936/" ]
``` file1 = open("some_file") file2 = open("other_file") for some_line,other_line in zip(file1,file2): #do something silly file1.close() file2.close() ``` note that `itertools.izip` may be prefered if you dont want to store the whole file in memory ... also note that this will finish when the end of either fil...
You can try the following code: ``` fin1 = open('file1') fin2 = open('file2') content1 = fin1.readlines() content2 = fin2.readlines() length = len(content1) for i in range(length): line1, line2 = content1[i].rstrip('\n'),content2[i].rstrip('\n') # do something fin1.close() fin2.close() ```
23,769,001
I would like to know if it is possible to enable gzip compression for Server-Sent Events (SSE ; Content-Type: text/event-stream). It seems it is possible, according to this book: <http://chimera.labs.oreilly.com/books/1230000000545/ch16.html> But I can't find any example of SSE with gzip compression. I tried to send ...
2014/05/20
[ "https://Stackoverflow.com/questions/23769001", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2753095/" ]
TL;DR: If the requests are not cached, you likely want to use zlib and declare Content-Encoding to be 'deflate'. That change alone should make your code work. --- If you declare Content-Encoding to be gzip, you need to actually use gzip. They are based on the the same compression algorithm, but gzip has some extra fr...
There's also middleware you can use so you don't need to worry about gzipping responses for each of your methods. Here's one I used recently. <https://code.google.com/p/ibkon-wsgi-gzip-middleware/> This is how I used it (I'm using bottle.py with the gevent server) ``` from gzip_middleware import Gzipper import bottl...
47,310,884
I need to passively install Python in my applications package installation so i use the following: ``` python-3.5.4-amd64.exe /passive PrependPath=1 ``` according this: [3.1.4. Installing Without UI](https://docs.python.org/3.6/using/windows.html#installing-without-ui) I use the PrependPath parameter which should ad...
2017/11/15
[ "https://Stackoverflow.com/questions/47310884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7031374/" ]
Ok, from my point of view it seems to be bug in Python Installer and I can not find any way how to make it works. I have founds the following workaround: Use py.exe which is wrapper for all version of Python on local machine located in C:\Windows so you can run it directly from CMD anywhere thanks to C:\Windows is st...
try powershell to do that ``` Start-Process -NoNewWindow .\python.exe /passive ```
47,310,884
I need to passively install Python in my applications package installation so i use the following: ``` python-3.5.4-amd64.exe /passive PrependPath=1 ``` according this: [3.1.4. Installing Without UI](https://docs.python.org/3.6/using/windows.html#installing-without-ui) I use the PrependPath parameter which should ad...
2017/11/15
[ "https://Stackoverflow.com/questions/47310884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7031374/" ]
Ok, from my point of view it seems to be bug in Python Installer and I can not find any way how to make it works. I have founds the following workaround: Use py.exe which is wrapper for all version of Python on local machine located in C:\Windows so you can run it directly from CMD anywhere thanks to C:\Windows is st...
Make sure you are using an elevated command prompt (ie: run as administrator).
47,310,884
I need to passively install Python in my applications package installation so i use the following: ``` python-3.5.4-amd64.exe /passive PrependPath=1 ``` according this: [3.1.4. Installing Without UI](https://docs.python.org/3.6/using/windows.html#installing-without-ui) I use the PrependPath parameter which should ad...
2017/11/15
[ "https://Stackoverflow.com/questions/47310884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7031374/" ]
Ok, from my point of view it seems to be bug in Python Installer and I can not find any way how to make it works. I have founds the following workaround: Use py.exe which is wrapper for all version of Python on local machine located in C:\Windows so you can run it directly from CMD anywhere thanks to C:\Windows is st...
> > Have you tried to use the InstallAllUsers argument. By default it is set >to 0 so try to use it like this (which is the same example from [here][1]): > > > python-3.6.0.exe /quiet InstallAllUsers=1 PrependPath=1 Include\_test=0 > it migth make a difference to use the `/quiet` over `/passive` > > > [1]: <https...
47,310,884
I need to passively install Python in my applications package installation so i use the following: ``` python-3.5.4-amd64.exe /passive PrependPath=1 ``` according this: [3.1.4. Installing Without UI](https://docs.python.org/3.6/using/windows.html#installing-without-ui) I use the PrependPath parameter which should ad...
2017/11/15
[ "https://Stackoverflow.com/questions/47310884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7031374/" ]
Ok, from my point of view it seems to be bug in Python Installer and I can not find any way how to make it works. I have founds the following workaround: Use py.exe which is wrapper for all version of Python on local machine located in C:\Windows so you can run it directly from CMD anywhere thanks to C:\Windows is st...
I also tried the command line options for the python installer and noticed the same issue as you, and here's the solution I found: 1. Download the 64-bit installer from here: <https://www.python.org/downloads/windows/> (the link is titled "*Windows x86-**64** executable installer*") 2. Uninstall any current python ins...
34,076,773
So i have an empty main frame called `MainWindow` and a `WelcomeWidget` that gets called immidiatley on program startup and loads inside the main frame. Then i want the button `next_btn` inside `WelcomeWidget` to call `LicenseWidget` QWidget inside the `MainWindow` class . How do i do that? Here is my code: **Main.py...
2015/12/03
[ "https://Stackoverflow.com/questions/34076773", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3855967/" ]
`QWizard` might be of use. Another way would be to layout both widgets in a `QVerticalLayout` and hide the one you are not interested in. The visible one takes then up all the space. It could even be completely constructed in QtCreator .. just `hide()` what you don't want to see and `show()` what you want to see. It ...
``` #!/usr/bin/env python # -*- coding: utf-8 -*- # # Main.py # # Copyright 2015 Ognjen Galic <gala@thinkpad> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the L...
56,914,224
I have a dataframe as shown in the picture: [problem dataframe: attdf](https://i.stack.imgur.com/9e5y4.png) I would like to group the data by Source class and Destination class, count the number of rows in each group and sum up Attention values. While trying to achieve that, I am unable to get past this type error:...
2019/07/06
[ "https://Stackoverflow.com/questions/56914224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9003184/" ]
@Adam.Er8 and @jezarael helped me with their inputs. The unhashable type error in my case was because of the datatypes of the columns in my dataframe. [Original df and df imported from csv](https://i.stack.imgur.com/soqF0.png) It turned out that the original dataframe had two object columns which i was trying to use ...
try using [`.agg`](https://pandas.pydata.org/pandas-docs/version/0.22/generated/pandas.core.groupby.DataFrameGroupBy.agg.html) as follows: ```py import pandas as pd attdf = pd.read_csv("attdf.csv") print(attdf.groupby(['Source Class', 'Destination Class']).agg({"Attention": ['sum', 'count']})) ``` Output: ``` ...
5,475,259
I run a small VPS with 512M memory of memory that currently hosts 3 very low traffic PHP sites and a personal email account. I have been teaching myself Django over the last few weeks and am starting to think about deploying a project. There seem to be a very large number of methods for deploying a Django site. Given...
2011/03/29
[ "https://Stackoverflow.com/questions/5475259", "https://Stackoverflow.com", "https://Stackoverflow.com/users/570068/" ]
There aren't really a great number of ways to do it. In fact, there's the recommended way - via Apache/mod\_wsgi - and all the other ways. The recommended way is fully documented [here](http://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/). For a low-traffic site, you should have no trouble fitting it in you...
Django has documentation describing possible [server arrangements](http://code.djangoproject.com/wiki/ServerArrangements). For light weight, yet very robust set up, I'd recommend Nginx setup. It's much lighter than Apache.
5,475,259
I run a small VPS with 512M memory of memory that currently hosts 3 very low traffic PHP sites and a personal email account. I have been teaching myself Django over the last few weeks and am starting to think about deploying a project. There seem to be a very large number of methods for deploying a Django site. Given...
2011/03/29
[ "https://Stackoverflow.com/questions/5475259", "https://Stackoverflow.com", "https://Stackoverflow.com/users/570068/" ]
There aren't really a great number of ways to do it. In fact, there's the recommended way - via Apache/mod\_wsgi - and all the other ways. The recommended way is fully documented [here](http://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/). For a low-traffic site, you should have no trouble fitting it in you...
I run several low-traffic Django sites on a 256 VPS without problem. I have Nginx setup as a reverse proxy and to serve static files (javascript, CSS, images) and Apache using mod\_wsgi for serving Django as described in the documentation. Running PHP sites as well may add a little overhead, but, if you're talking abo...
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
I ran into a similar problem. It turned out the CSV I had downloaded had no permissions at all. The error message from pandas did not point this out, making it hard to debug. Check that your file have read permissions
pandas read\_csv OSError: Initializing from file failed We could try `chmod 600 file.csv`.
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
I find the same problem under Win10 OS when I try to read a csv file which name is in Chinese. Then there's no problem any more after I rename my file into EN. Maybe you should ensure your full csv file path in EN. OS:Windows 10; Python version:3.6.5; Ipython:7.0.1; Pandas:0.23.0 First, when use ``` import pandas as...
pandas read\_csv OSError: Initializing from file failed We could try `chmod 600 file.csv`.
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
In my case, I was entering incorrectly the path. I was working with a dataset downloaded from Kaggle as a zip. The structure of downloads was: main.zip/subfiles.zip. I unzipped the main but the solution was to unzip the subfiles.zip and then my wanted file was within the subfiles.zip. So the path would be main/subfi...
OSError: Initializing from file failed By this error Python indicates the file is not readable- either, file permission, file error, incorrect path. etc. My code giving this error : ``` DataFrame=pd.read_csv("C:\\Users\\arindam\\Documents\\#Books & Docs\\#ML-DATA\\train.csv") ``` Fixed by this : ``` DataFrame=pd....
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
In my case, I was entering incorrectly the path. I was working with a dataset downloaded from Kaggle as a zip. The structure of downloads was: main.zip/subfiles.zip. I unzipped the main but the solution was to unzip the subfiles.zip and then my wanted file was within the subfiles.zip. So the path would be main/subfi...
just change the permessions of csv file, It would work chmod 750 filename.csv (in command line) or !chmod 750 filename.csv (in jupyter notebook)
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
I had the same issue, you should check your permissions. After `chmod 644 file.csv` it worked well.
Same problem when I was trying to load files with Japanese filenames. ``` import pandas as pd result = pd.read_csv('./result/けっこう.csv') OSError: Initializing from file failed' ``` Then I added an argument `engine="python"`. ``` result = pd.read_csv('./result/けっこう.csv', engine="python") ``` It worked for me.
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
``` import pandas as pd pd.read_csv("your_file.txt", engine='python') ``` Try this. It totally worked for me. * source : <http://kkckc.tistory.com/187>
OSError: Initializing from file failed By this error Python indicates the file is not readable- either, file permission, file error, incorrect path. etc. My code giving this error : ``` DataFrame=pd.read_csv("C:\\Users\\arindam\\Documents\\#Books & Docs\\#ML-DATA\\train.csv") ``` Fixed by this : ``` DataFrame=pd....
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
I had the same issue, you should check your permissions. After `chmod 644 file.csv` it worked well.
I find the same problem under Win10 OS when I try to read a csv file which name is in Chinese. Then there's no problem any more after I rename my file into EN. Maybe you should ensure your full csv file path in EN. OS:Windows 10; Python version:3.6.5; Ipython:7.0.1; Pandas:0.23.0 First, when use ``` import pandas as...
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
``` import pandas as pd pd.read_csv("your_file.txt", engine='python') ``` Try this. It totally worked for me. * source : <http://kkckc.tistory.com/187>
I had the same issue, you should check your permissions. After `chmod 644 file.csv` it worked well.
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
``` import pandas as pd pd.read_csv("your_file.txt", engine='python') ``` Try this. It totally worked for me. * source : <http://kkckc.tistory.com/187>
just change the permessions of csv file, It would work chmod 750 filename.csv (in command line) or !chmod 750 filename.csv (in jupyter notebook)
50,552,404
So far `pandas` read through all my CSV files without any problem, however now there seems to be a problem.. When doing: ``` df = pd.read_csv(r'path to file', sep=';') ``` I get: > > OSError Traceback (most recent call > last) in () > ----> 1 df = pd.read\_csv(r'path > Übersicht\Input\test\test.csv', sep=';') ...
2018/05/27
[ "https://Stackoverflow.com/questions/50552404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2252633/" ]
I ran into a similar problem. It turned out the CSV I had downloaded had no permissions at all. The error message from pandas did not point this out, making it hard to debug. Check that your file have read permissions
You can try using `os.path.join()` to build your path: ``` import os rpath = os.path.join('U:','folder','Input','test.csv') df = pd.read_csv(rpath, sep=';') ``` To traverse path based on your parent directory, you can use: ``` os.path.pardir ```
65,645,999
For some context, I am coding some geometric transformations into a python class, adding some matrix multiplication methods. There can be many 3D objects inside of a 3D "scene". In order to allow users to switch between applying transformations to the entire scene or to one object in the scene, I'm computing the geomet...
2021/01/09
[ "https://Stackoverflow.com/questions/65645999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10151432/" ]
One line: ```py def apply_centroid_transform(point, centroid, reverse=False): return [point[i] - [1, -1][reverse]*centroid[j] for i, j in enumerate('xyz')] ``` It is not very readable, but it is very concise :)
Well, if you like, you can do this: ``` def apply_centroid_transform(point, centroid, reverse=False): op = float.__sub__ if reverse else float.__add__ return [op(p_i, c_i) for p_i, c_i in zip(point, centroid)] ```
65,645,999
For some context, I am coding some geometric transformations into a python class, adding some matrix multiplication methods. There can be many 3D objects inside of a 3D "scene". In order to allow users to switch between applying transformations to the entire scene or to one object in the scene, I'm computing the geomet...
2021/01/09
[ "https://Stackoverflow.com/questions/65645999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10151432/" ]
How about ``` def apply_centroid_transform(point, centroid, reverse=False): if reverse: centroid["x"]= centroid["x"]*-1 centroid["y"]= centroid["y"]*-1 centroid["z"]= centroid["z"]*-1 new_point = [ point[0] - (centroid["x"]), point[1] - (centroid["y"]), point[2]...
Well, if you like, you can do this: ``` def apply_centroid_transform(point, centroid, reverse=False): op = float.__sub__ if reverse else float.__add__ return [op(p_i, c_i) for p_i, c_i in zip(point, centroid)] ```
65,645,999
For some context, I am coding some geometric transformations into a python class, adding some matrix multiplication methods. There can be many 3D objects inside of a 3D "scene". In order to allow users to switch between applying transformations to the entire scene or to one object in the scene, I'm computing the geomet...
2021/01/09
[ "https://Stackoverflow.com/questions/65645999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10151432/" ]
You are applying a scalar to the transformation and it just so happens that -1 moves a local object back to scene space. So, make the function generic and add a doc string. ``` def apply_centroid_transform(point, centroid, scalar=1): """Move point from centroid with scale. By default, scalar=1 and moves from s...
Well, if you like, you can do this: ``` def apply_centroid_transform(point, centroid, reverse=False): op = float.__sub__ if reverse else float.__add__ return [op(p_i, c_i) for p_i, c_i in zip(point, centroid)] ```
26,199,343
I have a bunch of `Album` objects in a `list` (code for objects posted below). 5570 to be exact. However, when looking at unique objects, I should have 385. Because of the way that the objects are created (I don't know if I can explain it properly), I thought it would be best to add all the objects into the list, and t...
2014/10/05
[ "https://Stackoverflow.com/questions/26199343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4027606/" ]
when you do mvvm and wanna use button then you should use DelegateCommand or RelayCommand. if you use this then you just have to implement the ICommand properly (CanExecute!) the Command binding to the button will handle IsEnabled for you. ``` <Button Command="{Binding MyRemoveCommand}"></Button> ``` cs. ``` pu...
As far as i can see in your MVVM there is a bool "CanRemove". You can bind this to your buttons visibility with the already [BooleanToVisibilityConverter](http://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter%28v=vs.110%29.aspx) which is provided by .NET
26,199,343
I have a bunch of `Album` objects in a `list` (code for objects posted below). 5570 to be exact. However, when looking at unique objects, I should have 385. Because of the way that the objects are created (I don't know if I can explain it properly), I thought it would be best to add all the objects into the list, and t...
2014/10/05
[ "https://Stackoverflow.com/questions/26199343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4027606/" ]
You don't need converter at all when you can access ViewModel directly using **`RelativeSource`** markup extension. This should work: ``` <Button IsEnabled="{Binding DataContext.CanRemove, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}}"/> ``` Since DataContext of ListBox points to ...
As far as i can see in your MVVM there is a bool "CanRemove". You can bind this to your buttons visibility with the already [BooleanToVisibilityConverter](http://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter%28v=vs.110%29.aspx) which is provided by .NET
26,199,343
I have a bunch of `Album` objects in a `list` (code for objects posted below). 5570 to be exact. However, when looking at unique objects, I should have 385. Because of the way that the objects are created (I don't know if I can explain it properly), I thought it would be best to add all the objects into the list, and t...
2014/10/05
[ "https://Stackoverflow.com/questions/26199343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4027606/" ]
You don't need converter at all when you can access ViewModel directly using **`RelativeSource`** markup extension. This should work: ``` <Button IsEnabled="{Binding DataContext.CanRemove, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}}"/> ``` Since DataContext of ListBox points to ...
when you do mvvm and wanna use button then you should use DelegateCommand or RelayCommand. if you use this then you just have to implement the ICommand properly (CanExecute!) the Command binding to the button will handle IsEnabled for you. ``` <Button Command="{Binding MyRemoveCommand}"></Button> ``` cs. ``` pu...
3,904,033
Is there an easy way to get a python code segment to run every 5 minutes? I know I could do it using time.sleep() but was there any other way? For example I want to run this every 5 minutes: ``` x = 0 def run_5(): print "5 minutes later" global x += 5 print x, "minutes since start" ``` That's only a fa...
2010/10/11
[ "https://Stackoverflow.com/questions/3904033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/472006/" ]
you can do it with the threading module ``` >>> import threading >>> END = False >>> def run(x=0): ... x += 5 ... print x ... if not END: ... threading.Timer(1.0, run, [x]).start() ... >>> threading.Timer(1.0, run, [x]).start() >>> 5 10 15 20 25 30 35 40 ``` Then when you want it to stop, set `E...
You might want to have a look at `cron` if you are running a \*nix type OS. You could easily have it run you program every 5 minutes <http://www.unixgeeks.org/security/newbie/unix/cron-1.html> <https://help.ubuntu.com/community/CronHowto>
3,904,033
Is there an easy way to get a python code segment to run every 5 minutes? I know I could do it using time.sleep() but was there any other way? For example I want to run this every 5 minutes: ``` x = 0 def run_5(): print "5 minutes later" global x += 5 print x, "minutes since start" ``` That's only a fa...
2010/10/11
[ "https://Stackoverflow.com/questions/3904033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/472006/" ]
you can do it with the threading module ``` >>> import threading >>> END = False >>> def run(x=0): ... x += 5 ... print x ... if not END: ... threading.Timer(1.0, run, [x]).start() ... >>> threading.Timer(1.0, run, [x]).start() >>> 5 10 15 20 25 30 35 40 ``` Then when you want it to stop, set `E...
If you are on a windows platform, you could use a scheduled task. Otherwise, use cron, wonderful, wonderful cron.
3,904,033
Is there an easy way to get a python code segment to run every 5 minutes? I know I could do it using time.sleep() but was there any other way? For example I want to run this every 5 minutes: ``` x = 0 def run_5(): print "5 minutes later" global x += 5 print x, "minutes since start" ``` That's only a fa...
2010/10/11
[ "https://Stackoverflow.com/questions/3904033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/472006/" ]
You might want to have a look at `cron` if you are running a \*nix type OS. You could easily have it run you program every 5 minutes <http://www.unixgeeks.org/security/newbie/unix/cron-1.html> <https://help.ubuntu.com/community/CronHowto>
If you are on a windows platform, you could use a scheduled task. Otherwise, use cron, wonderful, wonderful cron.
3,113,002
After doing web development (php/js) for the last few years i thought it is about time to also have a look at something different. I thought it may be always good to have look of different areas in programming to understand some different approaches better, so i now want to have look at GUI development. As programmin...
2010/06/24
[ "https://Stackoverflow.com/questions/3113002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/276382/" ]
The first thing to realize is that you'll get more mileage out of understanding Qt than understanding PyQt. Most of the good documentation discusses Qt, not PyQt, so getting conversant with them (and how to convert that code to PyQt code) is a lifesaver. Note, I don't actually recommend *programming* Qt in C++; Python ...
I had this bookmark saved: <http://www.harshj.com/2009/04/26/the-pyqt-intro/>
3,113,002
After doing web development (php/js) for the last few years i thought it is about time to also have a look at something different. I thought it may be always good to have look of different areas in programming to understand some different approaches better, so i now want to have look at GUI development. As programmin...
2010/06/24
[ "https://Stackoverflow.com/questions/3113002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/276382/" ]
I had this bookmark saved: <http://www.harshj.com/2009/04/26/the-pyqt-intro/>
My advice would be: have some particular goal in mind, some app that you, or even better someone else, would use in a real world scenario. I started with the same book Chris B mentioned, i.e. [Rapid GUI Programming with Python and Qt](http://www.qtrac.eu/pyqtbook.html) and I found it useful and it touched many of the ...
3,113,002
After doing web development (php/js) for the last few years i thought it is about time to also have a look at something different. I thought it may be always good to have look of different areas in programming to understand some different approaches better, so i now want to have look at GUI development. As programmin...
2010/06/24
[ "https://Stackoverflow.com/questions/3113002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/276382/" ]
The first thing to realize is that you'll get more mileage out of understanding Qt than understanding PyQt. Most of the good documentation discusses Qt, not PyQt, so getting conversant with them (and how to convert that code to PyQt code) is a lifesaver. Note, I don't actually recommend *programming* Qt in C++; Python ...
My advice would be: have some particular goal in mind, some app that you, or even better someone else, would use in a real world scenario. I started with the same book Chris B mentioned, i.e. [Rapid GUI Programming with Python and Qt](http://www.qtrac.eu/pyqtbook.html) and I found it useful and it touched many of the ...
3,113,002
After doing web development (php/js) for the last few years i thought it is about time to also have a look at something different. I thought it may be always good to have look of different areas in programming to understand some different approaches better, so i now want to have look at GUI development. As programmin...
2010/06/24
[ "https://Stackoverflow.com/questions/3113002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/276382/" ]
The first thing to realize is that you'll get more mileage out of understanding Qt than understanding PyQt. Most of the good documentation discusses Qt, not PyQt, so getting conversant with them (and how to convert that code to PyQt code) is a lifesaver. Note, I don't actually recommend *programming* Qt in C++; Python ...
There is a [step-by-step guide](http://popdevelop.com/2010/04/setting-up-ide-and-creating-a-cross-platform-qt-python-gui-application/) at popdevelop.com on how to set up Eclipse with PyQT.
3,113,002
After doing web development (php/js) for the last few years i thought it is about time to also have a look at something different. I thought it may be always good to have look of different areas in programming to understand some different approaches better, so i now want to have look at GUI development. As programmin...
2010/06/24
[ "https://Stackoverflow.com/questions/3113002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/276382/" ]
There is a [step-by-step guide](http://popdevelop.com/2010/04/setting-up-ide-and-creating-a-cross-platform-qt-python-gui-application/) at popdevelop.com on how to set up Eclipse with PyQT.
My advice would be: have some particular goal in mind, some app that you, or even better someone else, would use in a real world scenario. I started with the same book Chris B mentioned, i.e. [Rapid GUI Programming with Python and Qt](http://www.qtrac.eu/pyqtbook.html) and I found it useful and it touched many of the ...
18,905,026
When trying to unit test a method that returns a tuple and I am trying to see if the code accesses the correct tuple index, python tries to evaluate the expected call and turns it into a string. `call().methodA().__getitem__(0)` ends up getting converted into `'().methodA'` in my `expected_calls` list for the assertio...
2013/09/19
[ "https://Stackoverflow.com/questions/18905026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/373628/" ]
To test for `mock_object.account['xxx1'].patch(body={'status': 'active'})` I had to use the test: ``` mock_object.account.__getitem__.assert_has_calls([ call('xxxx1'), call().patch(body={'status': 'active'}), ]) ``` I can't explain why this works, this looks like weird behaviour, possibly a bug in mock, but ...
I've just stumbled upon the same problem. I've used the solution/work-around from here: <http://www.voidspace.org.uk/python/mock/examples.html#mocking-a-dictionary-with-magicmock> namely: ``` >> mock.__getitem__.call_args_list [call('a'), call('c'), call('d'), call('b'), call('d')] ``` You can skip the magic funct...
14,366,668
I've been working on learning python and somehow came up with following codes: ``` for item in list: while list.count(item)!=1: list.remove(item) ``` I was wondering if this kind of coding can be done in c++. (Using list length for the for loop while decreasing its size) If not, can anyone tell me why? ...
2013/01/16
[ "https://Stackoverflow.com/questions/14366668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948847/" ]
I am not a big Python programmer, but it seems like the above code removes duplicates from a list. Here is a C++ equivalent: ``` list.sort(); list.unique(); ``` As for modifying the list while iterating over it, you can do that as well. Here is an example: ``` for (auto it = list.begin(), eit = list.end(); it != ei...
In C++, you can compose something like this from various algorithms of the standard library, check out remove(), find(), However, the way your algorithm is written, it looks like O(n^2) complexity. Sorting the list and then scanning over it to put one of each value into a new list has O(n log n) complexity, but ruins t...
14,366,668
I've been working on learning python and somehow came up with following codes: ``` for item in list: while list.count(item)!=1: list.remove(item) ``` I was wondering if this kind of coding can be done in c++. (Using list length for the for loop while decreasing its size) If not, can anyone tell me why? ...
2013/01/16
[ "https://Stackoverflow.com/questions/14366668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948847/" ]
I am not a big Python programmer, but it seems like the above code removes duplicates from a list. Here is a C++ equivalent: ``` list.sort(); list.unique(); ``` As for modifying the list while iterating over it, you can do that as well. Here is an example: ``` for (auto it = list.begin(), eit = list.end(); it != ei...
Here's how I'd do it. ``` //If we will not delete an element of the list for (std::list<MyType>::iterator it = MyList.begin(); it != MyList.end();++it) { //my operation here } //If we will delete an element of the list for (std::list<MyType>::iterator it = MyList.begin(); it != MyList.end();) { std::list<MyType>::...
14,366,668
I've been working on learning python and somehow came up with following codes: ``` for item in list: while list.count(item)!=1: list.remove(item) ``` I was wondering if this kind of coding can be done in c++. (Using list length for the for loop while decreasing its size) If not, can anyone tell me why? ...
2013/01/16
[ "https://Stackoverflow.com/questions/14366668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948847/" ]
I am not a big Python programmer, but it seems like the above code removes duplicates from a list. Here is a C++ equivalent: ``` list.sort(); list.unique(); ``` As for modifying the list while iterating over it, you can do that as well. Here is an example: ``` for (auto it = list.begin(), eit = list.end(); it != ei...
In C++ you can in some conditions remove elements from a container while iterating over it. This depends on the container and on the operation you want to do. Currently there are different interpretations of your code snipplet in the different answers. My interpretation is, that you want to delete all the elements whi...
14,366,668
I've been working on learning python and somehow came up with following codes: ``` for item in list: while list.count(item)!=1: list.remove(item) ``` I was wondering if this kind of coding can be done in c++. (Using list length for the for loop while decreasing its size) If not, can anyone tell me why? ...
2013/01/16
[ "https://Stackoverflow.com/questions/14366668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948847/" ]
I am not a big Python programmer, but it seems like the above code removes duplicates from a list. Here is a C++ equivalent: ``` list.sort(); list.unique(); ``` As for modifying the list while iterating over it, you can do that as well. Here is an example: ``` for (auto it = list.begin(), eit = list.end(); it != ei...
I don't know Python but someone said in a comment that a list is equivalent to a C++ vector and it is not sorted, so here goes.... ``` std::vector<int> v{1, 2, 2, 2, 3, 3, 2, 2, 1}; v.erase(std::unique(v.begin(), v.end()), v.end()); ``` `v` contains `{1, 2, 3, 2, 1}` after this code. If the goal is to remove all du...
14,366,668
I've been working on learning python and somehow came up with following codes: ``` for item in list: while list.count(item)!=1: list.remove(item) ``` I was wondering if this kind of coding can be done in c++. (Using list length for the for loop while decreasing its size) If not, can anyone tell me why? ...
2013/01/16
[ "https://Stackoverflow.com/questions/14366668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948847/" ]
I am not a big Python programmer, but it seems like the above code removes duplicates from a list. Here is a C++ equivalent: ``` list.sort(); list.unique(); ``` As for modifying the list while iterating over it, you can do that as well. Here is an example: ``` for (auto it = list.begin(), eit = list.end(); it != ei...
`std::vector` is the container in C++ that is most similar to Python's `list`, and here's the correct way to modify a vector while iterating it: ``` template <typename T> void dedupe(std::vector<T> &vec) { for (std::vector<T>::iterator it = vec.begin(); it != vec.end(); ) { if (std::count(vev.begin(), vec....
49,889,153
I am running an RNN on a signal in fixed-size segments. The following code allows me to preserve the final state of the previous batch to initialize the initial state of the next batch. ``` rnn_outputs, final_state = tf.contrib.rnn.static_rnn(cell, rnn_inputs, initial_state=init_state) ``` This works when the batch...
2018/04/17
[ "https://Stackoverflow.com/questions/49889153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4008884/" ]
In tensorflow the only thing that is kept after returning from a call to `sess.run` are variables. You should create a variable for the state, then use `tf.assign` to assign the result from your RNN cell to that variable. You can then use that Variable in the same way as any other tensor. If you need to initialize the...
So, I came here looking for an answer earlier, but I ended up creating one. Similar to above posters about making it assignable... When you build your graph, make a list of sequence placeholders like.. ``` my_states = [None] * int(sequence_length + 1) my_states[0] = cell.zero_state() for step in steps: cell_ou...
38,552,688
I am trying to filter all the `#` keywords from the tweet text. I am using `str.extractall()` to extract all the keywords with `#` keywords. This is the first time I am working on filtering keywords from the tweetText using pandas. Inputs, code, expected output and error are given below. Input: ``` userID,tweetText...
2016/07/24
[ "https://Stackoverflow.com/questions/38552688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056548/" ]
If you are not too tied to using `extractall`, you can try the following to get your final output: ``` from io import StringIO import pandas as pd import re data_text = """userID,tweetText 01, home #sweet home 01, #happy #life 02, #world peace 03, #all are one """ data = pd.read_csv(StringIO(data_text),header=0) d...
The `extractall` function requires a regex pattern **with capturing groups** as the first argument, for which you have provided `#`. A possible argument could be `(#\S+)`. The braces indicate a capture group, in other words what the `extractall` function needs to extract from each string. Example: ``` data="""01, ho...
38,552,688
I am trying to filter all the `#` keywords from the tweet text. I am using `str.extractall()` to extract all the keywords with `#` keywords. This is the first time I am working on filtering keywords from the tweetText using pandas. Inputs, code, expected output and error are given below. Input: ``` userID,tweetText...
2016/07/24
[ "https://Stackoverflow.com/questions/38552688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056548/" ]
The `extractall` function requires a regex pattern **with capturing groups** as the first argument, for which you have provided `#`. A possible argument could be `(#\S+)`. The braces indicate a capture group, in other words what the `extractall` function needs to extract from each string. Example: ``` data="""01, ho...
Try this: Since it filters for '#', your NAN should not exist. ``` data = pd.read_csv(StringIO(data_text),header=0, index_col=0 ) data = data["tweetText"].str.split(' ', expand=True).stack().reset_index().rename(columns = {0:"tweetText"}).drop('level_1', 1) data = data[data['tweetText'].str[0] == "#"].r...
38,552,688
I am trying to filter all the `#` keywords from the tweet text. I am using `str.extractall()` to extract all the keywords with `#` keywords. This is the first time I am working on filtering keywords from the tweetText using pandas. Inputs, code, expected output and error are given below. Input: ``` userID,tweetText...
2016/07/24
[ "https://Stackoverflow.com/questions/38552688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056548/" ]
Set braces in your calculus : ``` fout = data['tweetText'].str.extractall('(#)') ``` instead of ``` fout = data['tweetText'].str.extractall('#') ``` Hope that will work
The `extractall` function requires a regex pattern **with capturing groups** as the first argument, for which you have provided `#`. A possible argument could be `(#\S+)`. The braces indicate a capture group, in other words what the `extractall` function needs to extract from each string. Example: ``` data="""01, ho...
38,552,688
I am trying to filter all the `#` keywords from the tweet text. I am using `str.extractall()` to extract all the keywords with `#` keywords. This is the first time I am working on filtering keywords from the tweetText using pandas. Inputs, code, expected output and error are given below. Input: ``` userID,tweetText...
2016/07/24
[ "https://Stackoverflow.com/questions/38552688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056548/" ]
If you are not too tied to using `extractall`, you can try the following to get your final output: ``` from io import StringIO import pandas as pd import re data_text = """userID,tweetText 01, home #sweet home 01, #happy #life 02, #world peace 03, #all are one """ data = pd.read_csv(StringIO(data_text),header=0) d...
Try this: Since it filters for '#', your NAN should not exist. ``` data = pd.read_csv(StringIO(data_text),header=0, index_col=0 ) data = data["tweetText"].str.split(' ', expand=True).stack().reset_index().rename(columns = {0:"tweetText"}).drop('level_1', 1) data = data[data['tweetText'].str[0] == "#"].r...
38,552,688
I am trying to filter all the `#` keywords from the tweet text. I am using `str.extractall()` to extract all the keywords with `#` keywords. This is the first time I am working on filtering keywords from the tweetText using pandas. Inputs, code, expected output and error are given below. Input: ``` userID,tweetText...
2016/07/24
[ "https://Stackoverflow.com/questions/38552688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056548/" ]
Set braces in your calculus : ``` fout = data['tweetText'].str.extractall('(#)') ``` instead of ``` fout = data['tweetText'].str.extractall('#') ``` Hope that will work
Try this: Since it filters for '#', your NAN should not exist. ``` data = pd.read_csv(StringIO(data_text),header=0, index_col=0 ) data = data["tweetText"].str.split(' ', expand=True).stack().reset_index().rename(columns = {0:"tweetText"}).drop('level_1', 1) data = data[data['tweetText'].str[0] == "#"].r...
22,714,864
I'm trying to craft a regex able to match anything up to a specific pattern. The regex then will continue looking for other patterns until the end of the string, but in some cases the pattern will not be present and the match will fail. Right now I'm stuck at: ``` .*?PATTERN ``` The problem is that, in cases where t...
2014/03/28
[ "https://Stackoverflow.com/questions/22714864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3472731/" ]
You could try using `split` If the results are of length 1 you got no match. If you get two or more you know that the first one is the first match. If you limit the split to size one you'll short-circuit the later matching: ``` "HI THERE THEO".split("TH", 1) # ['HI ', 'ERE THEO'] ``` The first element of the resul...
The Python documentation includes a brief outline of the differences between the `re.search()` and `re.match()` functions <http://docs.python.org/2/library/re.html#search-vs-match>. In particular, the following quote is relevant: > > Sometimes you’ll be tempted to keep using re.match(), and just add .\* to the front ...
22,714,864
I'm trying to craft a regex able to match anything up to a specific pattern. The regex then will continue looking for other patterns until the end of the string, but in some cases the pattern will not be present and the match will fail. Right now I'm stuck at: ``` .*?PATTERN ``` The problem is that, in cases where t...
2014/03/28
[ "https://Stackoverflow.com/questions/22714864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3472731/" ]
**One-Regex Solution** ``` ^(?=(?P<aux1>(?:[^P]|P(?!ATTERN))*))(?P=aux1)PATTERN ``` **Explanation** You wanted to use the atomic grouping like this: `(?>.*?)PATTERN`, right? This won't work. Problem is, you can't use lazy quantifiers at the end of an atomic grouping: the definition of the AG is that once you're out...
The Python documentation includes a brief outline of the differences between the `re.search()` and `re.match()` functions <http://docs.python.org/2/library/re.html#search-vs-match>. In particular, the following quote is relevant: > > Sometimes you’ll be tempted to keep using re.match(), and just add .\* to the front ...
62,461,709
currently, I'm trying to execute a python code that extracts information from the snowflake. When I running my code in my PC executed well, but if I try to run the code in a VM It shows me this error: [![enter image description here](https://i.stack.imgur.com/DTXuD.png)](https://i.stack.imgur.com/DTXuD.png) The VM is ...
2020/06/19
[ "https://Stackoverflow.com/questions/62461709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6153466/" ]
The Pandas python library requires some extra native libraries (DLLs) to load certain submodules due to use of C-extensions. Very recent Pandas versions, after 1.0.1, [are facing a build distribution issue](https://github.com/pandas-dev/pandas/issues/32857) currently, where their published packages are not carrying th...
Please make sure to have the [Snowflake Python Connector prerequisites](https://docs.snowflake.com/en/user-guide/python-connector-install.html#prerequisites) installed. You can try the following commands: ``` // Install Python sudo yum install python36 // Install pip curl https://bootstrap.pypa.io/get-pip.py -o get-...
36,676,629
I use the following trick in some of my Python scripts to drop into an interactive Python REPL session: ``` import code; code.InteractiveConsole(locals=globals()).interact() ``` This usually works well on various RHEL machines at work, but on my laptop (OS X 10.11.4) it starts the REPL seemingly without readline sup...
2016/04/17
[ "https://Stackoverflow.com/questions/36676629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6215905/" ]
Just `import readline`, either in the script or at the console.
The program `rlwrap` solves this problem in general, not just for Python but also for other programs in need of this feature such as `telnet`. You can install it with `brew install rlwrap` if you have Homebrew (which you should) and then use it by inserting it at the beginning of a command, i.e. `rlwrap python repl.py`...
21,421,987
Somewhat a python/programming newbie here. I am trying to access a specified range of tuples from a list of tuples, but I only want to access the first element from the range of tuples. The specified range is based on a pattern I am looking for in a string of text that has been tokenized and tagged by nltk. My code: ...
2014/01/29
[ "https://Stackoverflow.com/questions/21421987", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2680443/" ]
Probably the simplest method uses a [list comprehension](http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions). This statement creates a list from the first element of every tuple in your list: ``` print [tup[0] for tup in tagged[counter:counter+7]] ``` Or just for fun, if the tuples are always ...
Have you tried zip? also item[0] for item in name
21,421,987
Somewhat a python/programming newbie here. I am trying to access a specified range of tuples from a list of tuples, but I only want to access the first element from the range of tuples. The specified range is based on a pattern I am looking for in a string of text that has been tokenized and tagged by nltk. My code: ...
2014/01/29
[ "https://Stackoverflow.com/questions/21421987", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2680443/" ]
You can use like this: ``` result, _ = zip(*find_phrase()) print result ```
Probably the simplest method uses a [list comprehension](http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions). This statement creates a list from the first element of every tuple in your list: ``` print [tup[0] for tup in tagged[counter:counter+7]] ``` Or just for fun, if the tuples are always ...
21,421,987
Somewhat a python/programming newbie here. I am trying to access a specified range of tuples from a list of tuples, but I only want to access the first element from the range of tuples. The specified range is based on a pattern I am looking for in a string of text that has been tokenized and tagged by nltk. My code: ...
2014/01/29
[ "https://Stackoverflow.com/questions/21421987", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2680443/" ]
You can use like this: ``` result, _ = zip(*find_phrase()) print result ```
Have you tried zip? also item[0] for item in name
22,026,177
I'm getting a strange error from the Django tests, I get this error when I test Django or when I unit test my story app. It's complaining about multiple block tags with the name "content" but I've renamed all the tags so there should be zero block tags with the name content. The test never even hits my app code, and fa...
2014/02/25
[ "https://Stackoverflow.com/questions/22026177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1319434/" ]
You can use `while` and `each` like this: ``` while (my ($key1, $inner_hash) = each %foo) { while (my ($key2, $inner_inner_hash) = each %$inner_hash) { while (my ($key3, $value) = each %$inner_inner_hash) { print $value; } } } ``` This approach uses less memory than `foreach key...
You're looking for something like this: ``` for my $key1 ( keys %foo ) { my $subhash = $foo{$key1}; for my $key2 ( keys %$subhash ) { my $subsubhash = $subhash->{$key2}; for my $key3 ( keys %$subsubhash ) ```
22,026,177
I'm getting a strange error from the Django tests, I get this error when I test Django or when I unit test my story app. It's complaining about multiple block tags with the name "content" but I've renamed all the tags so there should be zero block tags with the name content. The test never even hits my app code, and fa...
2014/02/25
[ "https://Stackoverflow.com/questions/22026177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1319434/" ]
You're looking for something like this: ``` for my $key1 ( keys %foo ) { my $subhash = $foo{$key1}; for my $key2 ( keys %$subhash ) { my $subsubhash = $subhash->{$key2}; for my $key3 ( keys %$subsubhash ) ```
> > I'm just learning perl. > > > And you're already doing references. That's pretty good. > > I am trying to rewrite this multilevel loop using temporary variables so that I do not require the previous keys ($key1 $key2) to gain access(dereferencing) to $key3. What would be the easiest way of doing this. > > ...
22,026,177
I'm getting a strange error from the Django tests, I get this error when I test Django or when I unit test my story app. It's complaining about multiple block tags with the name "content" but I've renamed all the tags so there should be zero block tags with the name content. The test never even hits my app code, and fa...
2014/02/25
[ "https://Stackoverflow.com/questions/22026177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1319434/" ]
You can use `while` and `each` like this: ``` while (my ($key1, $inner_hash) = each %foo) { while (my ($key2, $inner_inner_hash) = each %$inner_hash) { while (my ($key3, $value) = each %$inner_inner_hash) { print $value; } } } ``` This approach uses less memory than `foreach key...
How about this: ``` foreach(values %foo){ foreach(values %$_){ foreach my $key3 (keys %$_){ print $key3; } } } ```
22,026,177
I'm getting a strange error from the Django tests, I get this error when I test Django or when I unit test my story app. It's complaining about multiple block tags with the name "content" but I've renamed all the tags so there should be zero block tags with the name content. The test never even hits my app code, and fa...
2014/02/25
[ "https://Stackoverflow.com/questions/22026177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1319434/" ]
You can use `while` and `each` like this: ``` while (my ($key1, $inner_hash) = each %foo) { while (my ($key2, $inner_inner_hash) = each %$inner_hash) { while (my ($key3, $value) = each %$inner_inner_hash) { print $value; } } } ``` This approach uses less memory than `foreach key...
> > I'm just learning perl. > > > And you're already doing references. That's pretty good. > > I am trying to rewrite this multilevel loop using temporary variables so that I do not require the previous keys ($key1 $key2) to gain access(dereferencing) to $key3. What would be the easiest way of doing this. > > ...
22,026,177
I'm getting a strange error from the Django tests, I get this error when I test Django or when I unit test my story app. It's complaining about multiple block tags with the name "content" but I've renamed all the tags so there should be zero block tags with the name content. The test never even hits my app code, and fa...
2014/02/25
[ "https://Stackoverflow.com/questions/22026177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1319434/" ]
How about this: ``` foreach(values %foo){ foreach(values %$_){ foreach my $key3 (keys %$_){ print $key3; } } } ```
> > I'm just learning perl. > > > And you're already doing references. That's pretty good. > > I am trying to rewrite this multilevel loop using temporary variables so that I do not require the previous keys ($key1 $key2) to gain access(dereferencing) to $key3. What would be the easiest way of doing this. > > ...
74,259,497
``` n: 8 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ``` How to print a number table like this in python with n that can be any number? I am using a very stupid way to pr...
2022/10/31
[ "https://Stackoverflow.com/questions/74259497", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20376552/" ]
If you have more than one reference to a list, then `.clear()` clears the list and preserves the references, but the assignment creates a new list and does not affect the original list. ``` a = [1,2,3] b = a # make an additional reference b.clear() print(a, b) # [] [] a = [1,2,3] b = a # make an additional reference b...
When you do `array.clear()`, that tells that existing object to clear itself. When you do `array = []`, that creates a brand-new object and replaces the one it had before. The new `array` object is unrelated to the one you stored in `self.array`.
33,617,551
I'm dealing with large raster stacks and I need to re-sample and clip them. I read list of Tiff files and create stack: ``` files <- list.files(path=".", pattern="tif", all.files=FALSE, full.names=TRUE) s <- stack(files) r <- raster("raster.tif") s_re <- resample(s, r,method='bilinear') e <- extent(-180, 180, -60, 9...
2015/11/09
[ "https://Stackoverflow.com/questions/33617551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2124725/" ]
I second @JoshO'Brien's suggestion to use GDAL directly, and `gdalUtils` makes this straightforward. Here's an example using double precision grids of the same dimensions as yours. For 10 files, it takes ~55 sec on my system. It scales linearly, so you'd be looking at about 33 minutes for 365 files. ``` library(gdalU...
For comparison, this is what I get: ``` library(raster) r <- raster(nrow=3000, ncol=7200, ymn=-60, ymx=90) s <- raster(nrow=2160, ncol=4320) values(s) <- 1:ncell(s) s <- writeRaster(s, 'test.tif') x <- system.time(resample(s, r, method='bilinear')) # user system elapsed # 15.26 2.56 17.83 ``` 10 files ...
71,344,145
So I'm making a very simple battle mechanic in python where the player will be able to attack, defend or inspect the enemy : ``` print("------Welcome To The Game------") player_hp=5 player_attack=3 enemy_hp=10 enemy_attack=2 while player_hp !=0 and enemy_hp !=0: Choice=input("""What will you do: A.Attack...
2022/03/03
[ "https://Stackoverflow.com/questions/71344145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18367808/" ]
You should not rely on sets to provide random arrangements of values. In this case you should use `random.randint` function. Example: ``` import random if Choice== "B": player_hp -= random.randint(1, 5) ``` Also as Shayan pointed out you are not modifying `player_hp` by doing `player_hp - ...` you should use `p...
> > how can I make it that everytime you press the defend option the value is different > > > You should look at using the `random` module Ignoring the game logic, here's a simple example ``` import random dice_values = list(range(1, 7)) # example for six-sided die alive = True while alive: value = random.c...
71,344,145
So I'm making a very simple battle mechanic in python where the player will be able to attack, defend or inspect the enemy : ``` print("------Welcome To The Game------") player_hp=5 player_attack=3 enemy_hp=10 enemy_attack=2 while player_hp !=0 and enemy_hp !=0: Choice=input("""What will you do: A.Attack...
2022/03/03
[ "https://Stackoverflow.com/questions/71344145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18367808/" ]
You should not rely on sets to provide random arrangements of values. In this case you should use `random.randint` function. Example: ``` import random if Choice== "B": player_hp -= random.randint(1, 5) ``` Also as Shayan pointed out you are not modifying `player_hp` by doing `player_hp - ...` you should use `p...
``` dice_roll=set(("1","2","3","4","5")) dice_list=list(dice_roll) value=dice_list[0] ... player_hp-4 elif value=="5": player_hp-5 ``` This code you created is a way of generating a random number, but there are better ways of doing this. --- Using the module `random`, you ca...
71,344,145
So I'm making a very simple battle mechanic in python where the player will be able to attack, defend or inspect the enemy : ``` print("------Welcome To The Game------") player_hp=5 player_attack=3 enemy_hp=10 enemy_attack=2 while player_hp !=0 and enemy_hp !=0: Choice=input("""What will you do: A.Attack...
2022/03/03
[ "https://Stackoverflow.com/questions/71344145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18367808/" ]
You should not rely on sets to provide random arrangements of values. In this case you should use `random.randint` function. Example: ``` import random if Choice== "B": player_hp -= random.randint(1, 5) ``` Also as Shayan pointed out you are not modifying `player_hp` by doing `player_hp - ...` you should use `p...
As the others have already recommended, I would also use the random function for an randomly chosen int between 1 and 5. If I understood your program correctly, in choice B you want the chosen value to be the players defence and the attack from the opponent to be subtracted from it. This would be my suggested solution ...
71,344,145
So I'm making a very simple battle mechanic in python where the player will be able to attack, defend or inspect the enemy : ``` print("------Welcome To The Game------") player_hp=5 player_attack=3 enemy_hp=10 enemy_attack=2 while player_hp !=0 and enemy_hp !=0: Choice=input("""What will you do: A.Attack...
2022/03/03
[ "https://Stackoverflow.com/questions/71344145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18367808/" ]
The problem is where you don't change the `enemy_hp` and `player_hp`! For example, when player choose to attack, then `enemy_hp` should decrease by `enemy_hp = enemy_hp-player_attack`. This is also necessary for `player_hp` too! So I think the code will be: ``` import random print("------Welcome To The Game------"...
> > how can I make it that everytime you press the defend option the value is different > > > You should look at using the `random` module Ignoring the game logic, here's a simple example ``` import random dice_values = list(range(1, 7)) # example for six-sided die alive = True while alive: value = random.c...
71,344,145
So I'm making a very simple battle mechanic in python where the player will be able to attack, defend or inspect the enemy : ``` print("------Welcome To The Game------") player_hp=5 player_attack=3 enemy_hp=10 enemy_attack=2 while player_hp !=0 and enemy_hp !=0: Choice=input("""What will you do: A.Attack...
2022/03/03
[ "https://Stackoverflow.com/questions/71344145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18367808/" ]
The problem is where you don't change the `enemy_hp` and `player_hp`! For example, when player choose to attack, then `enemy_hp` should decrease by `enemy_hp = enemy_hp-player_attack`. This is also necessary for `player_hp` too! So I think the code will be: ``` import random print("------Welcome To The Game------"...
``` dice_roll=set(("1","2","3","4","5")) dice_list=list(dice_roll) value=dice_list[0] ... player_hp-4 elif value=="5": player_hp-5 ``` This code you created is a way of generating a random number, but there are better ways of doing this. --- Using the module `random`, you ca...
71,344,145
So I'm making a very simple battle mechanic in python where the player will be able to attack, defend or inspect the enemy : ``` print("------Welcome To The Game------") player_hp=5 player_attack=3 enemy_hp=10 enemy_attack=2 while player_hp !=0 and enemy_hp !=0: Choice=input("""What will you do: A.Attack...
2022/03/03
[ "https://Stackoverflow.com/questions/71344145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18367808/" ]
The problem is where you don't change the `enemy_hp` and `player_hp`! For example, when player choose to attack, then `enemy_hp` should decrease by `enemy_hp = enemy_hp-player_attack`. This is also necessary for `player_hp` too! So I think the code will be: ``` import random print("------Welcome To The Game------"...
As the others have already recommended, I would also use the random function for an randomly chosen int between 1 and 5. If I understood your program correctly, in choice B you want the chosen value to be the players defence and the attack from the opponent to be subtracted from it. This would be my suggested solution ...
48,515,581
I have seen two ways of visualizing transposed convolutions from credible sources, and as far as I can see they conflict. My question boils down to, for each application of the kernel, do we go from many (e.g. `3x3`) elements with input padding to one, or do we go from one element to many (e.g. `3x3`)? *Related quest...
2018/01/30
[ "https://Stackoverflow.com/questions/48515581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747801/" ]
Strided convolutions, deconvolutions, transposed convolutions all mean the same thing. Both papers are correct and you don't need to be doubtful as both of them are [cited](https://scholar.google.com/) a lot. But the distil image is from a different perspective as its trying to show the artifacts problem. The first v...
Good explanation from Justin Johnson (part of the Stanford cs231n mooc): <https://youtu.be/ByjaPdWXKJ4?t=1221> (starts at 20:21) He reviews strided conv and then he explains transposed convolutions. ![](https://i.stack.imgur.com/h0xMp.png)
48,515,581
I have seen two ways of visualizing transposed convolutions from credible sources, and as far as I can see they conflict. My question boils down to, for each application of the kernel, do we go from many (e.g. `3x3`) elements with input padding to one, or do we go from one element to many (e.g. `3x3`)? *Related quest...
2018/01/30
[ "https://Stackoverflow.com/questions/48515581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747801/" ]
I want to stress a little more what Littleone also mentioned in his last paragraph: **A transposed convolution will reverse the spatial transformation of a regular convolution with the same parameters.** If you perform a regular convolution followed by a transposed convolution and both have the same settings (kernel ...
Good explanation from Justin Johnson (part of the Stanford cs231n mooc): <https://youtu.be/ByjaPdWXKJ4?t=1221> (starts at 20:21) He reviews strided conv and then he explains transposed convolutions. ![](https://i.stack.imgur.com/h0xMp.png)
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
Here is a way to do it in R: ``` # Variables: foo <- c("ARGHISLEULEULYS","METHISARGARGMET") # Code maps: code3 <- c("Ala", "Arg", "Asn", "Asp", "Cys", "Glu", "Gln", "Gly", "His", "Ile", "Leu", "Lys", "Met", "Phe", "Pro", "Ser", "Thr", "Trp", "Tyr", "Val") code1 <- c("A", "R", "N", "D", "C", "E", "Q", "G", "H", "I",...
Python 3 solutions. In my work, the annoyed part is that the amino acid codes can refer to the modified ones which often appear in the PDB/mmCIF files, like > > 'Tih'-->'A'. > > > So the mapping can be more than 22 pairs. The 3rd party tools in Python like > > Bio.SeqUtils.IUPACData.protein\_letters\_3to1 > ...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
Here is a way to do it in R: ``` # Variables: foo <- c("ARGHISLEULEULYS","METHISARGARGMET") # Code maps: code3 <- c("Ala", "Arg", "Asn", "Asp", "Cys", "Glu", "Gln", "Gly", "His", "Ile", "Leu", "Lys", "Met", "Phe", "Pro", "Ser", "Thr", "Trp", "Tyr", "Val") code1 <- c("A", "R", "N", "D", "C", "E", "Q", "G", "H", "I",...
Using R: ``` convert <- function(l) { map <- c("A", "R", "N", "D", "C", "E", "Q", "G", "H", "I", "L", "K", "M", "F", "P", "S", "T", "W", "Y", "V") names(map) <- c("ALA", "ARG", "ASN", "ASP", "CYS", "GLU", "GLN", "GLY", "HIS", "ILE", "LEU", "LYS", "MET", "PHE", "PRO"...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
Biopython has a nice solution ``` >>> from Bio.PDB.Polypeptide import * >>> three_to_one('ALA') 'A' ``` For your example, I'll solve it by this one liner ``` >>> from Bio.PDB.Polypeptide import * >>> str3aa = 'ARGHISLEULEULYS' >>> "".join([three_to_one(aa3) for aa3 in [ "".join(g) for g in zip(*(iter(str3aa),) * 3)...
Python 3 solutions. In my work, the annoyed part is that the amino acid codes can refer to the modified ones which often appear in the PDB/mmCIF files, like > > 'Tih'-->'A'. > > > So the mapping can be more than 22 pairs. The 3rd party tools in Python like > > Bio.SeqUtils.IUPACData.protein\_letters\_3to1 > ...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
Here is a way to do it in R: ``` # Variables: foo <- c("ARGHISLEULEULYS","METHISARGARGMET") # Code maps: code3 <- c("Ala", "Arg", "Asn", "Asp", "Cys", "Glu", "Gln", "Gly", "His", "Ile", "Leu", "Lys", "Met", "Phe", "Pro", "Ser", "Thr", "Trp", "Tyr", "Val") code1 <- c("A", "R", "N", "D", "C", "E", "Q", "G", "H", "I",...
For those who land here on 2017 and beyond: Here's a single line Linux bash command to convert protein amino acid three letter code to single letter code in a text file. I know this is not very elegant, but I hope this helps someone searching for the same and want to use single line command. ``` sed 's/ALA/A/g;s/CYS...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
BioPython already has built-in dictionaries to help with such translations. Following commands will show you a whole list of available dictionaries: ``` import Bio help(Bio.SeqUtils.IUPACData) ``` The predefined dictionary you are looking for: ``` Bio.SeqUtils.IUPACData.protein_letters_3to1['Ala'] ```
``` my %aa_hash=( Ala=>'A', Arg=>'R', Asn=>'N', Asp=>'D', Cys=>'C', Glu=>'E', Gln=>'Q', Gly=>'G', His=>'H', Ile=>'I', Leu=>'L', Lys=>'K', Met=>'M', Phe=>'F', Pro=>'P', Ser=>'S', Thr=>'T', Trp=>'W', Tyr=>'Y', Val=>'V', Sec=>'U', #http://www.uniprot.org/manu...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
``` >>> src = "ARGHISLEULEULYS" >>> trans = {'ARG':'R', 'HIS':'H', 'LEU':'L', 'LYS':'K'} >>> "".join(trans[src[x:x+3]] for x in range(0, len(src), 3)) 'RHLLK' ``` You just need to add the rest of the entries to the `trans` dict. **Edit:** To make the rest of `trans`, you can do this. File `table`: ``` Ala A Arg R ...
Another way to do it is with the [seqinr](https://cran.r-project.org/web/packages/seqinr/index.html) and [iPAC](http://www.bioconductor.org/packages/release/bioc/html/iPAC.html) package in R. ``` # install.packages("seqinr") # source("https://bioconductor.org/biocLite.R") # biocLite("iPAC") library(seqinr) library(iP...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
BioPython already has built-in dictionaries to help with such translations. Following commands will show you a whole list of available dictionaries: ``` import Bio help(Bio.SeqUtils.IUPACData) ``` The predefined dictionary you are looking for: ``` Bio.SeqUtils.IUPACData.protein_letters_3to1['Ala'] ```
Using R: ``` convert <- function(l) { map <- c("A", "R", "N", "D", "C", "E", "Q", "G", "H", "I", "L", "K", "M", "F", "P", "S", "T", "W", "Y", "V") names(map) <- c("ALA", "ARG", "ASN", "ASP", "CYS", "GLU", "GLN", "GLY", "HIS", "ILE", "LEU", "LYS", "MET", "PHE", "PRO"...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
Here is a way to do it in R: ``` # Variables: foo <- c("ARGHISLEULEULYS","METHISARGARGMET") # Code maps: code3 <- c("Ala", "Arg", "Asn", "Asp", "Cys", "Glu", "Gln", "Gly", "His", "Ile", "Leu", "Lys", "Met", "Phe", "Pro", "Ser", "Thr", "Trp", "Tyr", "Val") code1 <- c("A", "R", "N", "D", "C", "E", "Q", "G", "H", "I",...
Another way to do it is with the [seqinr](https://cran.r-project.org/web/packages/seqinr/index.html) and [iPAC](http://www.bioconductor.org/packages/release/bioc/html/iPAC.html) package in R. ``` # install.packages("seqinr") # source("https://bioconductor.org/biocLite.R") # biocLite("iPAC") library(seqinr) library(iP...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
``` my %aa_hash=( Ala=>'A', Arg=>'R', Asn=>'N', Asp=>'D', Cys=>'C', Glu=>'E', Gln=>'Q', Gly=>'G', His=>'H', Ile=>'I', Leu=>'L', Lys=>'K', Met=>'M', Phe=>'F', Pro=>'P', Ser=>'S', Thr=>'T', Trp=>'W', Tyr=>'Y', Val=>'V', Sec=>'U', #http://www.uniprot.org/manu...
Python 3 solutions. In my work, the annoyed part is that the amino acid codes can refer to the modified ones which often appear in the PDB/mmCIF files, like > > 'Tih'-->'A'. > > > So the mapping can be more than 22 pairs. The 3rd party tools in Python like > > Bio.SeqUtils.IUPACData.protein\_letters\_3to1 > ...
12,760,271
I have a fasta file as shown below. I would like to convert the [three letter codes](https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties) to one letter code. How can I do this with python or R? ``` >2ppo ARGHISLEULEULYS >3oot METHISARGARGMET ``` desired output ``` >2pp...
2012/10/06
[ "https://Stackoverflow.com/questions/12760271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1725152/" ]
For those who land here on 2017 and beyond: Here's a single line Linux bash command to convert protein amino acid three letter code to single letter code in a text file. I know this is not very elegant, but I hope this helps someone searching for the same and want to use single line command. ``` sed 's/ALA/A/g;s/CYS...
``` my %aa_hash=( Ala=>'A', Arg=>'R', Asn=>'N', Asp=>'D', Cys=>'C', Glu=>'E', Gln=>'Q', Gly=>'G', His=>'H', Ile=>'I', Leu=>'L', Lys=>'K', Met=>'M', Phe=>'F', Pro=>'P', Ser=>'S', Thr=>'T', Trp=>'W', Tyr=>'Y', Val=>'V', Sec=>'U', #http://www.uniprot.org/manu...
27,451,561
I'm new to stack so this might be a very silly mistake. I'm trying to setup a one node swift configuration for a simple proof of concept. I did follow the [instructions](http://docs.openstack.org/juno/install-guide/install/apt/content/ch_swift.html). However, something is missing. I keep getting this error: ``` root@l...
2014/12/12
[ "https://Stackoverflow.com/questions/27451561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/224982/" ]
`JSON.parse(data)` will turn the data you showing into a JavaScript object, and there are a TON of ways to use the data from there. Example: ``` var parsedData = JSON.parse(data), obj = {}; for(var key in parsedData['model']){ obj[key] = parsedData['model'][key]['id']; } ``` Which would give you a resulting...
You want to use JSON.parse(), but it returns the parsed object, so use it thusly: ``` var parsed = JSON.parse(data); ``` then work with parsed.
10,775,007
I want to create a python script which could be used to execute Android adb commands. I had a look at <https://github.com/rbrady/python-adb> but can't seem to make it work perfectly. Any suggestions?
2012/05/27
[ "https://Stackoverflow.com/questions/10775007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1391277/" ]
This tool should do the work. <https://pypi.python.org/pypi/pyadb/0.1.1> I had to modify a few functions to have it operate on Python 2.7 and use subprocess instead. Here the modified code in my version: ``` def __build_command__(self,cmd): if self.__devices is not None and len(self.__devices) > 1 and self.__targ...
Use a `monkeyrunner` tool for that. From it's [documentation](https://developer.android.com/studio/test/monkeyrunner/index.html): > > Besides using the monkeyrunner API itself, you can use the standard Python os and subprocess modules to call Android tools such as Android Debug Bridge. > > >
10,775,007
I want to create a python script which could be used to execute Android adb commands. I had a look at <https://github.com/rbrady/python-adb> but can't seem to make it work perfectly. Any suggestions?
2012/05/27
[ "https://Stackoverflow.com/questions/10775007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1391277/" ]
Use a `monkeyrunner` tool for that. From it's [documentation](https://developer.android.com/studio/test/monkeyrunner/index.html): > > Besides using the monkeyrunner API itself, you can use the standard Python os and subprocess modules to call Android tools such as Android Debug Bridge. > > >
The [python-adb](https://github.com/google/python-adb) project implements the USB communications layer and up, even providing an Android adb-like API for easy conversion.
10,775,007
I want to create a python script which could be used to execute Android adb commands. I had a look at <https://github.com/rbrady/python-adb> but can't seem to make it work perfectly. Any suggestions?
2012/05/27
[ "https://Stackoverflow.com/questions/10775007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1391277/" ]
This tool should do the work. <https://pypi.python.org/pypi/pyadb/0.1.1> I had to modify a few functions to have it operate on Python 2.7 and use subprocess instead. Here the modified code in my version: ``` def __build_command__(self,cmd): if self.__devices is not None and len(self.__devices) > 1 and self.__targ...
The [python-adb](https://github.com/google/python-adb) project implements the USB communications layer and up, even providing an Android adb-like API for easy conversion.
13,561,220
Think about this code: ``` #!/usr/bin/env python from threading import Thread count = 0 def test(): global count for i in range(10): count = count + 1 if __name__ == '__main__': for i in range(1000): Thread(target = test).start() print count ``` I use multiple threads, but the res...
2012/11/26
[ "https://Stackoverflow.com/questions/13561220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/802585/" ]
You do need one. Although multithreading works differently in Python, due to the [Global Interpreter Lock](http://wiki.python.org/moin/GlobalInterpreterLock), operations that are not atomic in Python-bytecode will still need locking. In you case, you can inspect the bytecode for your function `test` (`dis.dis(test)`):...
Definitely you should use Lock. You have got a correct answer in such simple case. Try to make it for range(100000) in **main**. You will see the problem. In my machine the result is 999960, but it is random result. Errors will arise depending on system load and so on.
13,561,220
Think about this code: ``` #!/usr/bin/env python from threading import Thread count = 0 def test(): global count for i in range(10): count = count + 1 if __name__ == '__main__': for i in range(1000): Thread(target = test).start() print count ``` I use multiple threads, but the res...
2012/11/26
[ "https://Stackoverflow.com/questions/13561220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/802585/" ]
You do need one. Although multithreading works differently in Python, due to the [Global Interpreter Lock](http://wiki.python.org/moin/GlobalInterpreterLock), operations that are not atomic in Python-bytecode will still need locking. In you case, you can inspect the bytecode for your function `test` (`dis.dis(test)`):...
You wouldn't need a lock if you just did assignments. But as you do `count = count + 1`, something can happen between each of reading out `count`, adding `1` and writing to `count`. Even using `count += 1` wouldn't solve this problem, as this involves an assignment as well. (As the inplace operations involve an assig...
13,561,220
Think about this code: ``` #!/usr/bin/env python from threading import Thread count = 0 def test(): global count for i in range(10): count = count + 1 if __name__ == '__main__': for i in range(1000): Thread(target = test).start() print count ``` I use multiple threads, but the res...
2012/11/26
[ "https://Stackoverflow.com/questions/13561220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/802585/" ]
You wouldn't need a lock if you just did assignments. But as you do `count = count + 1`, something can happen between each of reading out `count`, adding `1` and writing to `count`. Even using `count += 1` wouldn't solve this problem, as this involves an assignment as well. (As the inplace operations involve an assig...
Definitely you should use Lock. You have got a correct answer in such simple case. Try to make it for range(100000) in **main**. You will see the problem. In my machine the result is 999960, but it is random result. Errors will arise depending on system load and so on.
72,852,359
I would like to know if someone can answer why I cant seem to get a python gstreamer pipline to work without sudo in linux. I have a very small gstreamer pipline and it fails to open the gstreamer if I dont run with sudo infront of python. I have soon depleted my options, any help would be appriciated. (Using Jetson Or...
2022/07/04
[ "https://Stackoverflow.com/questions/72852359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8610564/" ]
accessToken is correct just don't forget use: ``` use Laravel\Passport\HasApiTokens; ``` instead of: ``` use Laravel\Sanctum\HasApiTokens; ``` This is correct: `$token = $user->createToken('Laravel Password Grant Client')->accessToken;`
you have to log in user first after the login token is created. $data['email'] = request email $data['password'] = request password ``` Auth::attempt($data); $loginUser = Auth::user(); $token = $loginUser->createToken('Laravel Password Grant Client')->accessToken; $loginUser->accessToken = $token; ```
72,852,359
I would like to know if someone can answer why I cant seem to get a python gstreamer pipline to work without sudo in linux. I have a very small gstreamer pipline and it fails to open the gstreamer if I dont run with sudo infront of python. I have soon depleted my options, any help would be appriciated. (Using Jetson Or...
2022/07/04
[ "https://Stackoverflow.com/questions/72852359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8610564/" ]
accessToken is correct just don't forget use: ``` use Laravel\Passport\HasApiTokens; ``` instead of: ``` use Laravel\Sanctum\HasApiTokens; ``` This is correct: `$token = $user->createToken('Laravel Password Grant Client')->accessToken;`
Just use `plainTextToken` instead of `accessToken`. ```php $token = $user->createToken('Laravel Password Grant Client')->plainTextToken; ``` It will give you a string, that you can use as API token.
64,472,414
I'm using `isbnlib.meta` which pulls metadata (book title, author, year publisher, etc.) when you enter in an isbn. I have a dataframe with 482,000 isbns (column title: isbn13). When I run the function, I'll get an error like `NotValidISBNError` which stops the code in it's tracks. What I want to happen is if there is ...
2020/10/21
[ "https://Stackoverflow.com/questions/64472414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12020223/" ]
* The current implementation for extracting isbn meta data, is incredibly slow and inefficient. + As stated, there are 482,000 unique isbn values, for which the data is being downloaded multiple times (e.g. once for each column, as the code is currently written) * It will be better to download all the meta data at onc...
Hard to answer without seeing the code, but [try/except](https://docs.python.org/3/tutorial/errors.html#handling-exceptions) should really be able to handle this. I am not an expert here, but look at this code: ``` l = [0, 1, "a", 2, 3] for item in l: try: print(item + 1) except TypeError as e: ...