Posts by Damião Martins • 275 points
17 posts
-
0
votes1
answer57
viewsA: Dynamic Form with Flask
*For now this answer is incomplete, it covers only the problem of form definition, missing how to render the HTML and database mapping. For the form, could do something with FieldList with FormField…
-
2
votes1
answer35
viewsA: Query to list the amount(Count) of records for a Foreign key
If you’re wondering how many orders were placed by each restaurant, you can use one GROUP BY to tell: SELECT idrestaurantepedido, count(distinct idpedido) as qtd_pedidos FROM pedidos GROUP BY…
-
2
votes2
answers73
viewsA: Using Regex to give match quotes after delimiter
This regex only picks up the quotation marks after the two dots: :\s+(\") Testing: https://regex101.com/r/a3vTyR/2…
-
0
votes1
answer30
viewsA: maximum hitNumber per visitID - google bigquery
You can use a Function window to find out the biggest user hitNumber and then filter only the hit that is equal to this hitNumber. It would be something like that: with user_hits as ( SELECT…
-
1
votes2
answers243
viewsA: Transform [hh:mm] into float (ex: 01:30 ==> 1.5) in python
Whereas the time is in a string, you could first separate the hours from the minutes: entrada = '01:35' hora, minuto = entrada.split(':') Then convert the minutes to the range of 0 to 1 and then add…
pythonanswered Damião Martins 275 -
0
votes2
answers43
viewsA: Why can’t I use Stringbuilder’s delete() method more than once in the same code block?
The problem is in the logic of your delete. The method indexOf return the word start index, so you need to consider the word size when passing to the method delete. If you do not, in the second…
-
0
votes1
answer47
viewsA: How to delete an element in python
What you can do is filter the unwanted lines from the dataframe using Loc and then select only the desired column: df_filtrado = df.loc[df['SEXO'] != 'Indefinido'] coluna_sexo = df_filtrado['SEXO']…
-
0
votes1
answer115
viewsA: How to add 2 objects and return number, in Python?
You can implement the method __radd__ in your class: class num(int): def __init__(self, n): self.n = n def __radd__(self, other): if isinstance(other, num): return self.n + other.n else: return…
-
0
votes1
answer63
viewsA: loop in json in flask using render_template
The first problem is that you are passing one string for the method render_template when using the json.dumps. You also do not need to convert the dataframe to json and then in dictionary, give to…
-
0
votes1
answer64
viewsA: How to find the accuracy between two columns of a data frame?
Considering a dataframe in the following format, as your example: >>> df ColA ColB 0 Bola Sola 1 Rua Rua And you want to count how many rows have the values of columns A and B equal, you…
-
0
votes2
answers82
viewsA: What is the real complexity behind Sleep Sort compared to the others?
The Sleep-Sort is not at all efficient, seems to have no use in the real world. In Wikiedia there is a topic about the problems of this algorithm: Based on this algorithm (written in Python) the…
-
0
votes2
answers72
viewsA: There is some difference between these two ways of Bubble Sort°
In some cases the first version, with while, may end with fewer iterations than the second. The second version is with some errors, how to use the i instead of j when switching positions in the…
-
0
votes2
answers1946
viewsA: Converting a String to Localdate
The code is not wrong, if the entry is 15/08/2020 it will work as expected. By doing String.valueOf(ld.minusDays(1)); the value returned will be in ISO format: yyyy-MM-dd. By so assigning in…
-
0
votes1
answer137
viewsA: How do I login to the database?
You can use the method fetchone the cursor to bring the first query result, it will be the line with the user data or None if you don’t find: def select_db(self, username, password): return…
-
1
votes2
answers39
viewsA: Delete string snippet whenever Python repeats
You can simply exchange the unwanted chunk for an empty string: df3['Nome da Seguradora'] = df3['Nome da Seguradora'].apply(lambda x: str(x).replace('_Soja_2020.xls',''))…
-
1
votes1
answer73
viewsA: Plot horizontally (column by column) - Python
You could put a snippet of XML to facilitate understanding. The way it is, you can just try to store the values in a list and then write to a file separated by comma. So when reading as csv it would…
-
1
votes1
answer71
viewsA: Download file setting the header
The way to pass the headers is correct. However, you are not passing any authentication headers, such as Authorization. You need to understand how the service expects this authentication and then…