Posts by lmonferrari • 3,550 points
179 posts
-
0
votes1
answer73
viewsA: I would like to edit my chart by displaying a single maximum value
I do not know if I have interpreted the question correctly, but it follows a possible solution: Complete code: library(readxl) library(dplyr) library(lubridate) df <-…
-
1
votes1
answer72
viewsA: How to plot the factors (spp) of the metaMDS result using ggplot2, related to the collection sites in the original data frame?
You can pivot: library(tidyr) library(dplyr) teste <- plt %>% pivot_longer( cols = starts_with('sp'), names_to = 'species', values_to = 'values' ) And then plot: ggplot(teste, aes(mds1, mds2,…
-
0
votes4
answers65
viewsA: I cannot print a list(vector)
Only change the size of aux or add - 1 will not work in the above case: Follow a solution based on your reasoning: n = int(input('Insira um número decimal para conversão em binário ')) cont = []…
-
0
votes1
answer32
viewsA: How to use 2-d numpy array with interactive panel floatslider for a python image Plot?
Imports: import numpy as np import holoviews as hv from holoviews import opts hv.extension('bokeh') import panel as pn pn.extension() The way I found it was passed as a direct parameter in its…
-
2
votes2
answers140
viewsA: How to verify if a poetic composition is a tautograma?
I did it in a simpler way to make it easier for you to understand: Putting the sentence in all minuscule letters to avoid comparison error: frase = 'Dentro desta devassa desilusão, Deixaste dias…
pythonanswered lmonferrari 3,550 -
0
votes4
answers457
viewsA: 4x4 matrix with 20 elements
You can use nested list comprehension: m = [[ input('Número') for i in range(4)] for x in range(4)] Entry of data manually: Número 1 Número 2 Número 3 Número 4 Número 5 Número 6 Número 7 Número 8…
-
1
votes1
answer76
viewsA: How to generate an ID to identify a student in a database with enrollments of several years?
Imports: import pandas as pd Loading the data: df = pd.read_csv('https://raw.githubusercontent.com/Renatolopo62/IFNMG-Januaria/master/dados/dados_padronizados_matriculas_januaria_2009_2018.csv')…
-
1
votes2
answers104
viewsA: How to identify the page number of a . pdf by something written on it?
Since the certificates follow the same order as the csv file: library(pdftools) arq <- read.csv('./rxt.csv') nomes <- as.character(arq$nome) cria_pdf <- function(n, i){…
-
4
votes2
answers136
viewsA: How to improve runtime
You can use groupby + value_counts of pandas: pd.set_option('display.max_rows', None) df.groupby(['NU_ANO_CENSO'])['Id'].value_counts() This line serves to remove the display limit if you are using…
-
0
votes1
answer492
viewsA: Attributeerror: 'Nonetype' Object has no attribute 'Insert' - Trying to insert a column
You must change it: df = df.drop(df[df.TPV == 0.00].index, inplace=True) df = df.insert(loc=25, column='Crédito BOAC', value=None) For that reason: df = df.drop(df[df.TPV == 0.00].index)…
-
0
votes1
answer68
viewsA: Is there any way to get Speechrecognition{python} to wait until the user speaks?
import speech_recognition as sr r = sr.Recognizer() while True : with sr.Microphone() as source: print("Diga algo!") audio = r.listen(source,timeout = None) try: print("Você disse: " +…
-
2
votes1
answer83
viewsA: Remove Repeated Elements from a List[0] from the List Database[1]
lista = [['pedro', 'marcos', 'mario', 'pedro', 'marcos', 'mario'],[5.2, 2.2, 6.1, 6.2, 1.1, 5.0]] nova_lista = [[],[]] for l, j in zip(lista[0], lista[1]): if l not in nova_lista[0]:…
-
4
votes2
answers51
viewsA: Special character removal in Software R
You can use the stringr package and call the str_replace_all function url <- "https://raw.githack.com/fulgenciomath/stackOverflow/master/futdata.csv" library(data.table) data <-…
ranswered lmonferrari 3,550 -
0
votes2
answers80
viewsA: How to clear lines on pandas using a list as a filter?
Importing and creating lists with values: import pandas as pd nome = ['foo','bar','fiz','zaz','foo','far','bar','fiz','cdd','boo','zuz','zuz'] valor = [2,3,2,5,6,7,2,9,6,3,8,10] listaFiltro =…
-
1
votes5
answers115
viewsA: Browse lists of different sizes
Of course, there are other ways to do this, but I tried to maintain the structure of your code. In this case I used the zip_longest package itertools to go through the lists according to the size of…
pythonanswered lmonferrari 3,550 -
0
votes2
answers280
viewsA: Replace use of dataframe with pandas . apply
I looked over and saw about . apply, but I couldn’t implement it. I would like to know if you could in that case, replace the use I use and for performance purposes, change to . apply. Importing the…
-
0
votes1
answer41
viewsA: Doubt in Python code using Tkinter
There were several minor errors in code and indentation Class code: from tkinter import* import pygame.mixer class SoundPanel(Frame): def __init__(self,app,mixer,arq_som): Frame.__init__(self,app)…
-
0
votes1
answer531
viewsA: Python graph does not show all values on the x-axis
Imports: import numpy as np import pandas as pd import matplotlib.pyplot as plt Estados Brasileiros: estados = np.array(['AC','AL','AP','AM','BA','CE', 'DF','ES','GO','MA','MT','MS',…
-
1
votes2
answers428
viewsA: How to return only repeated values in R?
library(readxl) library(dplyr) df <- read_xlsx('./coautoria.artigos.original.xlsx') df %>% add_count(artigo) %>% filter( n > 1) Have you tried using add_count? I don’t know if this is…
ranswered lmonferrari 3,550 -
0
votes5
answers9012
viewsA: How to replace more than one character in the replace method in Python 3?
texto = '@#$#$@!#$@!#$ AB C D DFGSFGS DFGS #$%@#$%@#%$,..,.,..3452345.1' caracter_esp = '.!?,@#%$ ' Here you enter with all the characters you want to remove caracter_esp = '.!?,@#%$ ', if you want…
-
0
votes5
answers14983
viewsA: How to merge multiple dates frames into one
You can use the function cbind which is from the base package of the R language: Using the data frame created by Carlos Cinelli: set.seed(1) df1 <- data.frame(id=1:10, y = rnorm(10)) df2 <-…
ranswered lmonferrari 3,550 -
1
votes4
answers573
viewsA: how to create a list of multiples of numbers of 3, from another list of numbers?
You can use list comprehension, which will return you a new list with multiples of 3: meus_numeros = [1, 56, 342, 12, 781, 23, 43, 45, 123, 567] nova_lista = [numero for numero in meus_numeros if…
-
2
votes1
answer51
viewsA: Web Scrapping R
Try to select using: html_node('.tabConteudo') library(rvest) url <- 'http://www2.bmf.com.br/pages/portal/bmfbovespa/boletim1/TxRef1.asp' pagina <- read_html(url) pagina a <- pagina %>%…
-
1
votes2
answers61
viewsA: How could I implement this code so that if I type "a" as 0 the program stops immediately and the message "END" appears?
That way you can: def conta(x,y,z): return (a**b)+c a = int(input('Infome a: ')) if a != 0: b = int(input('Infome b: ')) c = int(input('Infome c: ')) result = conta(a,b,c) print(result) else:…
pythonanswered lmonferrari 3,550 -
0
votes2
answers107
viewsA: Using for loop in a list with charts in R
In addition to Icarus Augustine’s response, you can use the apply family, which is more performative than the loop for: library(ggplot2) library(gridExtra) df <- data.frame(x = 1:100, y1 =…
-
0
votes2
answers123
viewsA: How to turn column into row in dataframe
Use the rbind function df1 = data.frame(c("MG","SP","RJ","ES","PA"),c("PA","ES","MG","SP","RJ")) colnames(df1) = c("Nome", "Estado") df2 =…
-
-1
votes3
answers5809
viewsA: How to fix "Valueerror: invalid literal for int() with base 10: '' - Python?
One way to solve this problem is by checking the size of the string you are receiving on saqueStr: def check_dezena(intDezena): if intDezena == 5: print(' 1 nota de R$ 50') elif intDezena > 5:…
-
0
votes2
answers118
viewsA: How to delete a specific PYTHON file
From what I saw your code has some unnecessary parts, I removed and updated. As you said you are trying to move the files between two folders I deleted that from code: serv =…
-
1
votes3
answers144
viewsA: Check magic numbers (those whose square root is a prime number) within a range
In the if pow(n,(1/2)) == 2 or 3 or 5 or 7 you should compare the result of the Pow with each item, in this example I put the prime numbers inside a list, so we use the operator 'in' to see if it…
pythonanswered lmonferrari 3,550