Posts by Sidon • 6,563 points
288 posts
-
0
votes1
answer198
viewsA: Warning looping Python Pandas, How to make the looping differently?
If I understand the question you only need a mask, see: import pandas as pd a = [[1,2,'n/a'],[2,1,'n/a'],[3,4,'n/a'],[4,3,'n/a']] candles = pd.DataFrame(a,columns=['askclose', 'askopen',…
-
0
votes1
answer338
viewsA: Signal change of values in Pandas Dataframe
[TL;DR] I designed a function that receives a dataframe, does not change it and returns another modified according to what Voce specifies.: import pandas as pd import numpy as np def ch_sign(df):…
-
2
votes1
answer207
viewsA: Kanade Lucas Tomasi (KLT) optical flow algorithm in Python
Opencv works with this (or variants of it) algorithm. Sparse Optical flow: These Algorithms, like the Kanade-Lucas-Tomashi (KLT) Feature tracker, track the Location of a few Feature points in an…
-
1
votes2
answers1297
viewsA: What is the difference between string.split(',') and string.rsplit(',') in python?
See these examples text = 'Essa, é, uma, string, de, teste' rs1 = text.rsplit(',',1) rs1 ['Essa, é, uma, string, de', ' teste'] rs2 = text.rsplit(',',2) rs2 ['Essa, é, uma, string', ' de', ' teste']…
-
2
votes2
answers77
viewsA: How to "reimport" an object from a Python module?
Before the possible solution, it is good to know: The Reload process is not fault-free because if it is certain that the variables are updated, it is not guaranteed that the old ones are removed,…
-
2
votes1
answer546
viewsA: Minimum value of each Python array column
Use np.min() import numpy as np a = np.array([[1,2,3],[10,20,30],[100,200,300],[1000,2000,3000]]) print(a) [[ 1 2 3] [ 10 20 30] [ 100 200 300] [1000 2000 3000]] min_cols = a.min(axis=1)…
-
0
votes1
answer630
viewsA: Python - Json : Keyerror
For you to understand your mistake do the following: 1) Place the json you present at the beginning of your question in a file called Infos.json (control-c/Contorl-v). 2) Open a python terminal and…
-
2
votes1
answer624
viewsA: Problem with Python Graph
I will try to answer based on the image of the example but without "doing homework", the first thing you need to do is to discover the parabola equation, realize that in the figure of the example…
-
1
votes3
answers2637
viewsA: Check if value is string or number
Considering only the decimal system (without taking into account hexa, octal, etc): valor='1' while valor!='0': valor = input('Digite o valor:') try: print(float(valor),' É um numero') except…
-
0
votes3
answers122
viewsA: Module Operator invokes special object methods
I will use the explanation of the book Fluent Python Ramalho: The first thing to know about special methods is that they were created to be called by the Python interpreter, not by Oce. We don’t…
-
1
votes1
answer122
viewsA: Loaning another Jango user
Use Django Qsessions Example of documentation (README, in the repository): Logout a user: for session in user.session_set.all(): session.delete() Example does not show where the variable comes from…
-
1
votes1
answer311
viewsA: How to reverse the association of one file to open with another in Pycharm
Menu File/Settings/Editor/File Types Look at the picture, it’s intuitive.…
-
2
votes2
answers78
viewsA: Check if directory 'B' is inside directory 'A'
Use Pathlib: from pathlib import Path def is_sub(root, directory): p = Path(root) return True if list(p.glob(directory)) else False Testing on Linux (ipython terminal) mkdir ~/teste1 cd ~/teste1…
-
1
votes4
answers1713
viewsA: Removing lines from a numpy array
TL;DR import numpy as np a1 = np.array([[ 1, 1, 1], [ 2, 2, 2], [ 3, 3, 3], [ 4, 4, 4], [ 5, 5, 5], \ [ 6, 6, 6], [ 7, 7, 7], [ 8, 8, 8], [ 9, 9, 9], [10, 10, 10], [11, 11, 11], \ [12, 12, 12], [13,…
-
2
votes1
answer422
viewsA: ADD Column - Django
Unless you are not using the Django ORM, this operation is done automatically by the framework. Follow the steps below: Go to your app’s models.py file, model definition (class) and simply add the…
-
2
votes1
answer61
viewsA: How to sort items from a list using two different values?
If I understood and/or implemented correctly, the result will be different from what Oce presents, I will order the list of dictionaries, there is only vc adapt to your context: # Ordenando…
-
2
votes1
answer546
viewsA: How to open a txt file and use to print what I want
Try So: Create a file called.txt file with the names you want, so do it: import codecs wordList = codecs.open('Arquivo.txt' , 'r').readlines() for w in wordlist: print(referencia(w[:-1])) Pythonism:…
-
1
votes1
answer279
viewsA: ERROR - DJANGO 2.0.9 - Typeerror: create_superuser() Missing 1 required positional argument: 'email'
In the definition of the User class, where you inform USER_NAME_FIELD, add EMAIL_FIELD, like this: class User(AbstractBaseUser, PermissionsMixin): username = models.CharField('Nome de Usuário',…
-
0
votes3
answers92
viewsA: As I do in python for at the end of the code, it go to the start again
import threading def my_function(): threading.Timer(3600, my_function).start() print("Hello, World!") my_function() See working on repl it., I put 5 seconds for you to see how it works.…
-
0
votes1
answer942
views -
3
votes2
answers2868
viewsA: How to know which libraries are being used in a python project?
Quickly and carelessly you can "fix", doing so: In the environment of your project do: $ pip freeze > requirements.txt In the production environment, do: $ pip install -r requirements.txt Because…
-
1
votes2
answers1353
viewsA: No module named 'urls' in Django
By the message, your module urls can not be imported for some reason, let’s create a minimalist project to see how it works: Create a Django project in a temporary directory: $ django-admin…
-
0
votes1
answer95
viewsA: Error in Python2
[TL;DR] Try it like this: from sklearn.naive_bayes import MultinomialNB import numpy as np vaca1= [1,1,0] vaca2= [1,1,0] vaca3= [1,1,0] cavalo4= [1,1,1] cavalo5= [0,1,1] cavalo6= [0,1,1] dados =…
-
2
votes2
answers943
viewsA: Use of if __name__=='__main__'. Why is the class not instantiated?
I see that you already have an answer with a good theoretical explanation, so I will answer without worrying about the functioning of Testecase, based on the comments, I will try to induce the…
-
2
votes1
answer4205
viewsA: Convert PDF to text with Python
Being a PDF an image, to extract the texts is necessary an OCR package (it is necessary to keep in mind that these packages may not have 100% of hit), there are several of them in python, for what…
-
1
votes1
answer959
viewsA: Sort dictionary by value and use rule if value is first python
Python dictionaries are not "orderly". There are several other objects that can be sorted in python, so I suggest you use one of them and then transfer them to an Ordereddict dictionary (which,…
-
1
votes1
answer554
viewsA: Problem with reading python files
After reading the file you need to extract the contents of it (with readlines, for example), before that the variable is a text.IOwrapper and not a string. Behold: str1 = open(file, 'r') str2 =…
-
0
votes1
answer595
viewsA: check if two keys in a dictionary have equal values
d1 = {'A': ['B', 'C'], 'B': ['A', 'C'], 'C': ['A', 'B'], 'D': ['B', 'C']} To test total equality d1['A']==d1['D'] True d1['A']==d1['B'] False Or specifically for your question, looking for elements…
-
2
votes1
answer1093
viewsA: Remove repeated words using python
Instead of opening the files like this: wordList = codecs.open('Arquivo.txt' , 'r') wordList2 = codecs.open('Arquivo2.txt', 'w') Try it like this: wordList = codecs.open('Arquivo.txt' ,…
-
3
votes1
answer848
viewsA: Display only hours, minutes and seconds on a graph whose input is in Unix time
[TL;DR] Below is an example with the use of pandas, based on it Voce can easily adapt your code, it is not mandatory to use pandas, after example I make a suggestion to adapatr your code:…
-
1
votes2
answers400
viewsA: What are the statements placed before strings?
Enter a python 2.7 terminal and do: str1 = 'teste' str2 = 'teste' Now look at the two of you: type(str1) str type(str2) unicode Python 2 needs the u' to indicate that the string is Unicode (to work…
-
0
votes2
answers159
viewsA: nodejs installation on Ubuntu
[TL;DR] $ sudo ln -s /usr/bin/nodejs /usr/bin/node Probably when Voce installed the nodejs from the apt-get installer, Node was still a version earlier than 0.10.x, to quickly resolve run the above…
-
1
votes2
answers2940
viewsA: How do I import a jupyter notebook ? or open?
In the directory where is the file you want to open, in the command line, type: jupyter notebook, and then you have a new service "listening" at gate 8888, see: $ jupyter notebook [I 10:51:49.289…
-
5
votes1
answer424
viewsA: Graph of Machine Learning
[TL;DR] Without the original data it is difficult to be sure that it is not with them, so I created random data to test with the code you present and the chart was successfully plotted, see: import…
-
1
votes1
answer340
viewsA: Polynomial class - list assignment index out of range
[TL;DR] Try it like this: class Polinomio: def __init__ (self, termos = None, n = 0): self.termos = termos or [] self.n = [0] * n def __len__ (self): return len(self.termos) def __setitem__ (self,…
-
3
votes2
answers1404
viewsA: What’s the "self" for?
Although in another language, this question was answered in STO itself. So I just did an assignment: The reason you need to use the self is because Python does not use the syntax @ to refer to the…
-
1
votes1
answer7534
viewsA: Count elements of a column
[TL;DR] Pandas Now I understood the file format, I do not know if I completely understood the goal, so I made a version based on pandas, which counts the occurrences of each word in each column.…
-
1
votes2
answers4702
viewsA: How to convert date difference from seconds to hours/days?
TL;DR* The question seems to be truncated, but it seems to indicate that you want to know the difference between the current date and the date of creation of something, ie the difference between two…
-
1
votes1
answer94
viewsA: Import: No module named manages.alert.views
Try this in your home directory: $ mkdir teste1 $ cd teste1 $ mkdir gerencia $ touch gerencia/__init__.py $ mkdir gerencia/alert $ touch gerencia/alert/__init__.py The tree should look like this: .…
-
15
votes1
answer2502
viewsA: What are the differences between Flask and Django?
For those who are already working with a framework, it is relatively easy to understand, Flask is a micro-framework while Django is a Fullstack framework. A Fullstack framework like Django already…
-
1
votes1
answer3370
viewsA: Object is not subscriptable error
You’re wearing brackets on open when you should be wearing parentheses. Instead of : with open['tabela.csv', 'a'] as f: Try: with open('tabela.csv', 'a') as f:…
-
2
votes2
answers1443
viewsA: How to make a nested FOR?
lista = ['iPhone 6', 'Apple', 'Android','Samsung'] text = ''' iPhone 6 é um dispostivo da Apple. iPhone 6 não é da Samsung, iPonhe 6 é da Apple ''' for l in lista: …
-
2
votes1
answer8561
viewsA: Removing Row from Nan values of a Dataframe
Dropna import pandas as pd import numpy as np df = pd.DataFrame([[np.nan, 2, np.nan, 0], [3, 4, np.nan, 1], [np.nan, np.nan, np.nan, 5]], columns=list('ABCD')) df A B C D 0 NaN 2.0 NaN 0 1 3.0 4.0…
-
1
votes1
answer222
viewsA: Installing and configuring the Lamp Stack on Ubuntu
Updating the system: $ sudo apt-get update $ sudo apt-get upgrade Installing the Apache: $ sudo apt-get install apache2 Starting the apache: $ systemctl restart apache2 Test the installation by…
-
1
votes1
answer2323
viewsA: Mounting table from a csv, grouped by week, with python and pandas
TL;DR I noticed that you already applied that response, and exported the resulting table to a csv And now you want to set up the final table from reading it, right? Since Voce left images and not…
-
0
votes1
answer807
viewsA: How to install Java 8 32bit on Linux Deepin x86_64
Download the java here; Double click on the package and put it in /tmp or go to the shell and... $ tar xvzf ~/Downloads/jdk-8*.tar.gz -C /tmp/ On the command line, create a directory, if it does not…
-
1
votes2
answers1093
viewsA: Group by week
Since you’re using pandas to read the csv, I suggest you use your own functions to resolve this issue. Surely there must be several ways to do this with the pandas, I will present to you the one…
-
1
votes1
answer334
viewsA: Error in html Django?
I don’t know if it was a mistake in control-c/control-v, but the way your code should not even compile, your Texts is breaking line without the scape for it. Besides, it makes no sense to put only…
-
1
votes2
answers61
viewsA: default values for namedtuple
No python3 use .__new__.__defaults__ to assign default values. Points = namedtuple('Points', 'x y z') Points.__new__.__defaults__ = (None,None,'Foo') Points() Points(x=None, y=None, z='Foo')…
-
1
votes1
answer11835
viewsA: Sort Python Data Frame (Pandas) in two levels
I was in doubt if I understood completely, so I created a new version of the data and includes 3 times Albania with different years to check the result. import pandas as pd import io # Simulando um…