Posts by Sidon • 6,563 points
288 posts
-
1
votes2
answers113
viewsA: Generator Expressions
(TL;DR) Generating expressions, or genexp is a very broad subject in python, but maybe what you need is list comprehensions or listcomps, I’ll try to give an example here using the approach, with…
-
2
votes1
answer1686
viewsA: Python/Pandas - How to remove extra space between two words from a data frame column
import pandas as pd rdata = {'NAME': [' José Luiz da Silva ']} df = pd.DataFrame(rdata, columns = ['NAME']) for i, row in df.iterrows(): df.set_value(i,'NAME',' '.join(row.NAME.split())) print (df)…
-
4
votes1
answer2986
viewsA: Free API for Weather History
Openweathermap: "Our API is simple, clean and digratis. We offer high-level support (paid plans). For API access, Voce needs to create an account to get a Key API." Link to the website.…
-
1
votes2
answers1079
viewsA: How to compare if the contents of two columns string of a data frame are similar
(TL;DR) Testing the rate of similarity between two strings: # Testando taxa de similaridade from difflib import SequenceMatcher def sml(x,y): return SequenceMatcher(None, x, y).ratio() x = 'José…
-
3
votes2
answers3218
viewsA: Nano for Windows
Install Bash on windows: The instructions here only serve for windwos 10 from Build 14316, if using a previous build, upgrade your system. Access windows 10 settings by clicking the Start menu and…
-
6
votes1
answer581
viewsA: How to get the 10 most frequent words from in array?
(TL;DR) Collections: import collections # Lista de palavras words = ['Banana', 'Maçã','Laranja', 'Melão','Uva','Abacaxi','Abacate','Pimenta','Banana',…
-
2
votes2
answers5844
viewsA: Python/Pandas - How to create a data frame that contains the original line and duplicate line
(TL;DR) Building the dataframe from the data: import pandas as pd import numpy as np from collections import OrderedDict data = OrderedDict( { 'País': ['Bélgica', 'Índia', 'Brasil','Índia'],…
-
0
votes1
answer1521
viewsA: Files deleted by Django Migrations
Problems with Migrations are very common in the Django universe, as I have seen reports that in complex scenarios some teams prefer to create mechanisms to disable migrations. After some time of…
-
0
votes3
answers50
viewsA: Returning information recorded in the bank
It’s been a while since I’ve programmed in Delhi, but I think it would look something like this: qry1.post qry2.post ... qryN.post try: commit except Implmentação…
-
0
votes2
answers426
viewsA: Object Syntax Problems in Json?
Try it like this: {"shoppings": [ { "nome": "Bangu Shopping", "licenseKey":"0", "acessKey":"0", "secretKey":"0", "latitude1":["-22.879832"], "latitude2":["-22.877738"], "longitude1:":["-43.468601"],…
-
0
votes1
answer4942
viewsA: Python/Pandas - How to create a "str" column from another numeric, including zero on the left when the value is less than 9
A quick way to do this (TL;DR): Creating the new column: df['com_zeros'] = '0' Applying the condition:: for b in df.itertuples(): df.com_zeros[b.Index] = '0'+str(b.battles) if b.battles<9 else…
-
5
votes2
answers876
viewsA: Is it possible for me to create a runtime class in Python?
(TL;DR) It is possible and indeed relatively easy, although laborious. I will reproduce an explanation/example well spread on the Internet: First of all, let’s focus on the relationship between type…
-
2
votes1
answer487
viewsA: Get and Set using PROPERTY - Python3
I created a small example that by default has the value of the dollar in 3.3, Voce can change and access this value in a class instance through the property and Setter us. (TL;DR) class Convert: def…
-
2
votes2
answers742
viewsA: What is Python’s native support for database manipulation?
In my opinion, in languages that support the OO paradigm, it is much more productive to use a ORM (when available) for access to relational banks. In the case of python, if I’m not using a Framework…
-
4
votes3
answers6545
viewsA: Run script written in Python in windows (No python installed)
You can "package" python along with your script, by your question, it seems to me that the most appropriate would be a "python Compiler", two interesting options are: Nuitka: TL;DR Nuitica is a…
-
6
votes1
answer4262
viewsA: Latex and Python integration
Reportlab: With reportlab Voce you can generate pdfs without the need to generate one .tex, but if you know latex and the task you are doing is academic and/or scientific, I would opt for Pylatex.…
-
0
votes3
answers205
viewsA: How to get mime from a file through Python?
shlex: import subprocess import shlex file_name = 'pdf.fake' cmd = shlex.split('file --mime-type {0}'.format(file_name)) result = subprocess.check_output(cmd) mime_type = result.split()[-1] print…
-
3
votes1
answer611
viewsA: Using an external folder function
Just turn the folder 1 into a python package by putting an empty file with the name __init__.py, from there just import the functions you want from that package. Example with Hello World: Create a…
-
1
votes1
answer715
viewsA: Custom select on DJANGO
Simple as that: class Categ(models.Model): categ_desc=models.CharField('categ', max_length=100) def __str__(self): return self.categ_desc class Produto(models.Model): nome=models.CharField('nome',…
-
1
votes1
answer346
viewsA: .htaccess to prevent navigation
Try this: <Location /my_folder/> Order Deny,Allow Deny from all </Location> Or this (depends on the server version) <directory /my_folder/> Order Deny,Allow Deny from all…
-
3
votes3
answers4694
viewsA: How is the structure of projects in python?
If Voce will use the "pure" python structure as you wish, including the way you did in your previous language, of course adapting to the particularities of python. Now... if you are going to use…
-
1
votes2
answers1095
viewsA: Add a new value at the beginning of a pandas series
Edited (Insertion in the middle of the series): I did an analysis in the middle of the series, see in the code. Try the code below, see it running here. import pandas as pd serie = pd.Series() for n…
-
1
votes3
answers760
viewsA: Doubt with IF and LISTS python3
If Voce is going to use python for infrastructure management tasks in the linux environment, my suggestion is that you do, first of all; this: pip install plumbum Plubum: (tl;dr) With this package…
-
2
votes1
answer160
viewsA: How to improve log file visualization?
Actually parsing logs is a very boring task, but depending on the context Voce can use some tools such as pipe (|) followed by grep, for example, say you want to "inspect" syslog for events…
-
2
votes2
answers161
viewsA: I can’t convert to whole
I don’t know if I understand the question, but if your goal is only to validate ip, use the appropriate libraries for this, see the code below. Bonus: Information about the correctly typed ip.…
-
1
votes1
answer3343
viewsA: Login to site with POST request in python?
I believe that the ideal would be through an API, usually these services provide API’s with procedures for access, the ideal would be to check this before. If unavailable, try Lenium. Selenium An…
-
1
votes4
answers1960
viewsA: Back position in data JSON format or list with Python
I think they have already given good answers here, but I will leave my interpretation, even to make the analysis requested in the comments. The first thing I notice is that the example that is given…
-
2
votes2
answers399
viewsA: Problem with while repetition structure
I don’t know if I understand the question, but come on: See the code running on rel.it. import getpass def login(): usr = 'Admin' while True: user = str(input('Usuário: ')) if user != usr:…
-
0
votes2
answers150
viewsA: Inner Join Database
I can’t test here, but I believe what you need is a subquery, SELECT FROM SELECT, test there and tell me if it works (you may have to make some adjustment): SELECT NOME, DISCIPLINA, MAX(MEDIA) AS…
-
3
votes1
answer329
viewsA: Sending emails at scheduled times
Schedule: "Schedule allows you to perform Python functions (or any other callable) periodically at predetermined intervals, using a user-friendly syntax". Example of Repo in git: $ pip install…
-
2
votes1
answer247
viewsA: Which framework do you recommend for javascript unit testing (Ecmascript 6)?
This is the type of subjective question that can have several answers, also subjective, since it is the type of question that can generate answers based on opinions. I’m going to name three with…
-
0
votes3
answers664
viewsA: How do I upload all the files in the directory except for a specific one?
Add only what you’ve changed: git add -u Sumario git add -A Tudo que estiver em staging git add . Tudo em stage, e modificados git add -u stage modificados e deletados, novos ignorados.…
-
0
votes2
answers77
viewsA: Local backup with online access
If you have ssh access there are several ways to do this, but since you say you have ftp access, Voce can access from most modern browsers, just put the ftp address in the browser address bar, for…
-
1
votes2
answers756
viewsA: Creating a regex for vowels in C
As you said you "need a regex", I thought to present only the regex "pure", without worrying about the language, but I would have to test it somehow, so I developed in python (I have this regex here…
-
0
votes1
answer212
viewsA: Create XML template file in Intellij Idea Jetbrain
Go on: File | Settings | Editor | File Types, click on the plus sign + to add a new type.…
-
3
votes2
answers441
viewsA: Python dot notation ( methods )
Let’s start with an example where 4 methods are created, being a init, the first two with the notation show(obj) and the last with the call that you call 'point notation''. See the code presented in…
-
0
votes1
answer391
viewsA: Javascript Problem - Spring Boot Dependent Combos
I don’t know Spring Boot so I’ll leave an example in "Pure JS". You can see running too here on codepen and here at the Fiddle. // By Sidon | 2017 // Fiddle version:…
-
1
votes3
answers4627
viewsA: How to return empty record from a Select?
Edited, In detail. With this Voce version you get the detailed information about the fields: SELECT r.RDB$FIELD_NAME AS field_name, r.RDB$DESCRIPTION AS field_description, r.RDB$DEFAULT_VALUE AS…
-
0
votes2
answers1283
viewsA: Delete contents including folders
Edited, Script: The first version does not delete the subfolders, so try the script below: del /q "C:\Teste\*.*" FOR /D %%p IN ("C:\Teste\*.*") DO rmdir "%%p" /s /q mkdir teste cd \teste mkdir files…
-
2
votes2
answers206
viewsA: Difficulty accessing json
Edited: Article: Note that Elements is also a rray of objects ("Distance" and "Duration") and that this array (Elements) is within another array that is rows, then for you to access an object of…
-
0
votes1
answer2191
viewsA: Email with Python attachment
I will focus on sending a PDF, without trying to adapt your code: import smtplib # Trabalhando com mimetypes import mimetypes # Modulos para manipulação de email import email import…
-
4
votes2
answers225
viewsA: Regexp extract value
Edited, final version Meets 2 templates with one regex. This version results in a tuple with numerical values. As the regex meets the 2 templates, the tuple will always return 4 items, 2 of them…
-
3
votes1
answer6789
viewsA: Find the input of a certain value in a Python list
I won’t settle the matter for you, but here are some tips: Checking if an element is embedded in a list: >>> 5 in [1,2,3,4,5] True Using index: >>> [1,2,3,4,5].index(2) 3 looking…
-
4
votes2
answers2031
viewsA: Find smallest string from a python list
Edited (New version): Actually my original version is totally wrong, I did not notice the fact that what the question asks is the smallest "size" of the string and not the smallest value. As I also…
-
1
votes1
answer1152
viewsA: Create visual loading screens in python
I used the character '#' instead of '-' which is the default, code below, run on a console to see the result, adapt the function test() for your context. import time def progress_bar(done):…
-
0
votes1
answer154
viewsA: What Method to Send Email in Python?
Straight from the documentation: Creating and sending a simple email: # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email.mime.text…
-
1
votes1
answer2905
viewsA: Segment image and highlight object border using python
Really this image "is bone", and your question even more, :-), but maybe applying something more related to segmentation, you can have better results. import cv2 import numpy as np from matplotlib…
-
0
votes1
answer236
viewsA: Python Error in if
Okay, after the real chat in the comments, and you’ve sent me the csv’s, "solved your problem" (don’t let that happen again, Ahahaha), let’s go. The problem is that you need to compare each row of…
-
1
votes1
answer444
viewsA: Update values from a chart using Django
Yes, the idea of storing the data in the bank is good, but if Oce does not need to persist them, since they are temporary, this strategy would consume the bank’s resources, unnecessarily. I would…
-
1
votes3
answers2758
viewsA: How to print without line break in Python
If I understood the question, one possible solution would be this: # Criando a string com 441 zeros zeros = 441*'0' # Variável para a divisão da string split = 21 # Criando a "matriz" a partir da…