Posts by Lucas • 3,858 points
153 posts
-
5
votes2
answers65
viewsA: Delete prepositions and text articles in python
What you are looking for is called "stopwords" and is a type of filtering traditionally used in natural language processing. See an example using the nltk package: import nltk…
-
2
votes2
answers172
viewsQ: How to scrape Qlikview tables using Nodejs?
This website of the Brazilian government presents salary data to judges of various courts and tribunals. I would like to download all tables, but the data relating to the tables are not in the html…
-
4
votes1
answer123
viewsQ: What is the difference between the rest operator (%) in Python and Rust?
Writing a small program in Rust, I noticed that the operator results % are different from what I get in Python for negative numbers. For example, in Python -4 % 26 returns 22, but in Rust: fn main()…
-
1
votes1
answer24
viewsA: Removing non-numerical value from a dataframe
One option is to use the regex option of replace: df.replace('\.+', np.nan, regex=True) Following example replicable: import pandas as pd import numpy as np df = pd.DataFrame({'A': [0, 1, 2, 3, 4],…
-
3
votes2
answers144
viewsA: What are the differences between constants declared with const and immutable variables declared with Let in Rust?
TL;DR: Immutable variables declared with let are only common variables, except that they cannot be changed throughout the program. Constants, created with const, are a completely different type,…
-
1
votes2
answers65
viewsQ: How do local modules work in Go?
I saw in this question that it is possible to define local modules in Go using the GOPATH. However, in the solution of this question, the file is not used go.mod What is this file for? There is a…
-
1
votes2
answers65
viewsA: How do local modules work in Go?
The question solution is correct and works even in the latest versions of Go. However, since version 1.11 it is possible to use a module manager that makes it possible to define packages within a…
-
1
votes1
answer27
viewsQ: How to use PIL floodfill in python?
I am trying to color a bar using python’s PIL package. This is the original bar: I would like to color the entire inner part with just one color. I tried to use the floodfill for that reason: from…
-
0
votes1
answer42
viewsA: Add data within a dataframe based on a condition for two columns
If you always have this structure, you can just use groupby: df.groupby(['A','B']).agg({'C':'sum'}).reset_index()
-
0
votes1
answer62
viewsA: How to receive and send data from an React application to a Flask API?
As suggested in the comments, it is possible to use the same function fetch to send an object to the flask API. This requires adding some parameters to the function: useEffect(() => { const…
-
0
votes1
answer62
viewsQ: How to receive and send data from an React application to a Flask API?
I am making an app in React and would like to use Flask to save user data in a local database. I was able to make React and flask "run on the same door" and thus enable a connection between them.…
-
2
votes1
answer30
viewsA: How to add more values in a numpy matrix?
The problem with your code is that every time the loop passes, it creates the line again. That’s why you only get one line at the end. An array is basically a list of lists, so you can use the…
-
6
votes1
answer85
viewsQ: What’s the difference between mod and Rust?
I understand the workings of the keyword mod, explained in this matter. For users of Python, mod works exactly like the keyword import. That is, to use functions and other objects defined in a file…
-
5
votes1
answer53
viewsQ: What good is lib.rs in Rust?
As shown in this question, in Rust it is possible to import a file (its structs, functions, etc) using the keyword mod. For example, in the following directory structure: src/ main.rs…
-
2
votes0
answers31
viewsQ: Is it possible to create private methods for Python classes?
In Rust, it is possible to create a module where some methods associated with a struct are private. I understand that the utility of this is to make available to the end user of the module only the…
-
0
votes1
answer33
viewsA: Separate Dataframe Column in List
What you need is a pivot_table: table=pd.pivot_table(data=df,index='Label',values='Porcentagem', columns='Categoria').fillna(0) print([table[k].to_list() for k in table.columns]) Output: [[40.0,…
-
6
votes1
answer303
viewsA: What is the difference between Random.Choice and Random.Choices in Python?
There are two fundamental differences: random.choice returns an element of the drawn sequence, while random.choices returns a list of elements of the drawn sequence random.choices accepts weights…
-
3
votes3
answers81
viewsQ: Is it possible to use functions in an arbitrary order in C++?
Apparently, the order in which functions are written matters in C++. Example, this code compiles: #include <iostream> using namespace std; int add_number(int x, int y){ return x+y; } int…
-
6
votes1
answer130
viewsQ: What is the difference of syscall and call in Assembly?
The following simple code I wrote, based on a code I read in a book, was not compiling: ;myhello section .data msg db "Boa tarde",0 NL db 0xa section .bss section .text global main main: push rbp…
-
1
votes1
answer108
viewsQ: How to get binary code from a string without ASCII characters in Python?
I’m studying Unicode and encodings. I understand so far that Unicode is a key-value structure in which each character is represented by a number. Example: import string…
-
3
votes1
answer48
viewsQ: What is the point of using Option as a type in the argument of a function?
I’m trying to use a function that has as argument a variable of type Option. An example without Option: fn main() { next10(9); } fn next10(n: i32) { for i in n..n+10 { println!("{}", i) } } An…
-
0
votes0
answers45
viewsQ: How to extract pdf string in Rust?
I’m trying to use the package pdf_extract to manipulate pdfs in Rust. I would like to extract the string from the pdf. I saw that the function for this is set so: pub fn extract_text<P:…
-
5
votes1
answer44
viewsQ: How to use Result in user-defined function?
Many Rust functions apply the enumerable Result in its implementation. This enumerable makes it easy to manage error, since you can use unwrap or expect to help identify the error in a code. An…
-
4
votes1
answer124
viewsQ: What does the "value used here after move" error mean in Rust?
I am studying Rust and would like to better understand when I can and when I can’t use the same variable more than once in the same scope. I leave below two examples. In the first, the program works…
-
1
votes1
answer56
viewsQ: What is export for FLASK_APP and FLASK_ENV?
I’m learning flask now and understand that every time I run my application, I need to run before: export FLASK_APP=app.py export FLASK_ENV=development I just memorized that I need to do this, but I…
-
-1
votes1
answer76
viewsQ: How to receive user data and return function value using flask?
I have a project where I would like to apply a python function using user-given information and return the function result to html. I know you normally use javascript for these cases, but my…
-
3
votes2
answers84
viewsQ: How to access the position of multiple matchs of a regex in a string?
I know I can access the position of a match of a regex in a string using the methods start, end and span. Example of a program that identifies repetitions in a text: import re from colorama import…
-
7
votes2
answers87
viewsQ: What is the relationship between unhashable and mutable?
I always use strings as keys in dictionaries, but, studying the theme, I noticed that it is possible to use any immutable object. So, in addition to strings, dictionaries accept as keys objects such…
-
2
votes1
answer60
viewsQ: What use is memoryview in Python?
I am reading about arrays in Python and came across a function built in call memoryview. I understood that a difference from lists to arrays is that in the latter it is possible to use the…
-
4
votes1
answer50
viewsQ: Why does C syntax work to create variable range limit in bash?
I tried to create a variable limit in a range for a for loop in bash using a function. Follow my code: function tree(){ let var=$1 for i in {1..$var} do echo $i done } tree 5 To my frustration, this…
-
2
votes3
answers68
viewsA: Regular expression to take one or more occurrences that precede and follow a given letter
In this case what you need is to use (\w+\se\s\w+) as a group and place a quantifier. See: let text1 = "olá meu numero é trezentos e vinte e quatro tudo bem?"; let text2= "olá meu número é quarenta…
-
1
votes1
answer64
viewsA: Remove words after specific python character
One option is to use regex: import re degrees="Master's degree (M.A., M.S., M.Eng., MBA, etc.)" print(re.findall(r'.+(?=\s\()', degrees)) Returns: ["Master's degree"] The regular expression (?=...)…
-
-1
votes1
answer45
viewsA: Select to calculate all records and total record by one condition
One solution is to make two queries and join them with a LEFT JOIN. See example: CREATE DATABASE example; use example; CREATE TABLE sales (id INT, product_name VARCHAR(100), VALOR INT); INSERT INTO…
-
0
votes1
answer28
viewsA: Questions with COUNT/GROUP BY
One solution is to make two separate queries and put them together: CREATE DATABASE example; use example; CREATE TABLE impact (id INT, quantidade INT, impacto VARCHAR(100)); INSERT INTO impact…
-
0
votes1
answer29
viewsQ: How to create an id variable from a query result?
I’m doing a query of a table that doesn’t have a variable id, but I’d like to assign a id to my result. The following example: Sample basis: CREATE DATABASE breaking; use breaking; CREATE TABLE…
-
0
votes1
answer71
viewsA: Search for similar names or with typo - Mysql
One option is to use REGEXP. Following replicable example: CREATE DATABASE supermarket; use supermarket; CREATE TABLE products (id INT, name VARCHAR(100)); INSERT INTO products (id,name) VALUES…
-
1
votes2
answers54
viewsA: Why does creating a list with the same generator only work the first time?
What you have is a Generator and the value in question erases from memory after you use it. For example, the elements of the variable: pares=(k for k in range(10) if k%2==0) can be accessed by the…
-
1
votes1
answer40
viewsA: How to define my package name in Pypi?
All metadata of your package (such as name, version, author, etc.) are in the file setup.py. Here an example file of this type: from distutils.core import setup setup( name = 'YOURPACKAGENAME',…
-
1
votes1
answer54
viewsA: How to annotate an individual chart using facet_grid?
One option is to create another data.frame, add only text coordinate information to it and use geom_text to write down. See: graph<- ggplot(Dados,aes(x = Temp, y = Gly, shape = Accesion))…
-
0
votes1
answer34
viewsQ: How to merge SQL when the key variable repeats in one of the tables?
I have a dataset with two tables. In the first, I have information of workers and in the second of firms. Each of the workers has a id of the firm you belong to. I would like to create a new table…
-
2
votes2
answers41
views -
2
votes1
answer49
viewsQ: Is it possible to filter an SQL base based on a list of values?
On pandas, when I want to filter one DataFrame based on a list of values, I: valores=[15,17,22] df=df[[k in valores for k in df.mpg]] In SQL I know I can get the same result with the following code:…
-
2
votes1
answer35
viewsA: Center values from each bar on matplotlib charts using Python
The plt.text has as arguments the x-axis value, the y-axis value and the string to be used. In this command plt.text(i, qtd[i], qtd[i]) you’re saying "put the text at position x=i and y=Qtd[i]". As…
-
0
votes1
answer90
viewsQ: Error "mkdir: Missing operand"
I am trying to create a series of folders on my computer that start with strings from "01" to "20". To do this, I created a list of strings and applied the command mkdir in an iteration: declare -a…
-
2
votes2
answers38
viewsA: Comparison of content in matrices
One solution is to use the builtin function all to check that all line elements are equal to the first: tab2 = [ ['X','O','X'], ['X','X','X'], ['O','O','O'], ] def is_equal(row): return…
-
2
votes1
answer142
viewsA: How to remove scientific notation on the y-axis using matplotlib?
1e7 is indicating that the scale is in tens of millions (10 7). In general, it is recommended to move the scale to millions (10 6) or thousands (10 3) to facilitate the reading of the graph. But if…
-
2
votes1
answer38
viewsA: How do I convert string values or items from an object column into binary with pandas?
A solution using map: data['Class'].map({'positive':1,'negative':0}) Note that this solution serves several categories. In the specific case of binary variables, there is the get_dummies. In your…
-
4
votes4
answers1234
viewsA: Python - Calculate transposed matrix
A solution using list comprehension: A=[[1,2],[4,6]] #printa as linhas da matriz A for i in A: print(i) A_t=[[k[0] for k in A],[k[1] for k in A]] #printa as linhas da transposta de A for i in A_t:…
-
2
votes1
answer82
viewsA: How can I know the title of a Youtube video while downloading?
The solution is to use ydl.extract_info: import youtube_dl ydl = youtube_dl.YoutubeDL() result = ydl.extract_info('https://www.youtube.com/channel/UCVJqulBlIchaIsGFK-hCKFQ', download=False) for i in…
-
2
votes2
answers63
viewsA: How to add a new column with the group average in pandas?
An alternative to the lmonferrari solution is to use the method transform: dataset['Media_GolsCasa']=dataset.groupby("Home")["Gols Casa"].transform("mean")…