Posts by afonso • 748 points
31 posts
-
0
votes1
answer98
viewsA: Python - Ignore Nan values in a . csv and add the rest
Using the method sum, you can specify the parameter value skipna to exclude NaNs: totalQuantidade = df['Quantidade'].sum(skipna=True)…
-
1
votes2
answers54
viewsA: Separate extension name - in Python
You can extract the values directly through the methods Extract and replace of Series pandas. import pandas as pd data = ['Ismael (100)', 'JEFFERSON LUIZ ESTEVAO DE MOURA (111)', 'Felipe Braga Regis…
-
2
votes1
answer99
viewsA: Coding Problem Between Javascript Client and Python Server
You’re confusing concepts. The library socket [Python-Docs] is different from websockets. In your case, you want to implement a websocket to communicate between the Python server and the browser…
-
2
votes3
answers723
viewsA: Python: conditional sum with variable condition
You can perform this sum using the method cumsum after doing the groupby per company: df = pd.DataFrame({"empresa":["HST", "HST", "HST", "HSC", "HSC","HSC","HSC"], "produto":["prod1", "prod2",…
-
1
votes2
answers100
viewsA: Dataframe row and column organization
The code below has been tested with the pandas-1.0, and using the function pivot_table [Pandas-Docs] allows you to convert the dataframe for the desired format: df.columns=['col1', 'col2', 'col3']…
-
0
votes2
answers28
viewsA: Ordering result
You can use the method sorted, specifying the key to be used in the comparison. In this case: def palavras(texto): palavras = converte_texto(texto) contagem = dict() for palavra in palavras :…
-
0
votes1
answer249
viewsA: Create permissions on Django
Once you’ve defined the relationship OneToOne between the User and the UserTecnico you can do the validation with: {% if user.usertecnico.is_pode_acessar %} <p> Este código só pode ser visto…
-
0
votes1
answer162
viewsA: Noreversematch at /
I think the problem is related to the urls in show_annoucement.html. The variable course within the context Ourse is with lowercase "c": {% extends "courses/course_dashboard.html" %} {% block…
-
1
votes1
answer207
viewsA: Noreversematch at /view_clients/
Two things to change: In your urlpatterns you must correct to: urlpatterns = [ path('', views.index, name='index'), path('view_clients/', views.clientes, name='clientes'),…
-
3
votes3
answers11645
viewsA: Using Groupby in Pandas dataframe
Using the function groupby: df[['Nome', 'Dia']].groupby('Nome').agg(lambda x: list(set(x))).reset_index() Out[6]: Nome Dia 0 Antonio [24] 1 Carlos [4, 28] 2 Jose [1, 2] 3 Pedro [24, 3] dtype: object…
-
1
votes2
answers2626
viewsA: How to make a "procv" in Python using the Pandas library
We can make a Unstack after a Groupby: df.groupby('Nome')['Vendas'].apply(lambda df: df.reset_index(drop=True)).unstack(0)…
-
1
votes1
answer1271
viewsA: How to make a dynamic table in a Pandas dataframe?
You can make that count through a groupby: df.groupby(['VLAN','Interface']).size().reset_index().rename(columns={0:'contagem'})
-
2
votes1
answer938
viewsA: Take values from a column of a dataframe and create a column in another with the corresponding values
You can do it using the method merge, specifying the column where to do the join (in this case the equipe) df1 = df1.merge(df2, on='equipe', how='left')…
-
4
votes1
answer365
viewsA: What is the right way to perform performance tests in Python?
Essentially you have two quick ways to test the performance of each method. You can choose to run each function within the function timeit.(): def foo(): # ... duration = timeit.timeit(foo,…
-
1
votes1
answer163
viewsA: How to use user-clicked button text as input in Tkinter?
One possible solution is to create two new functions: one to generate new questions and the other associated with buttons Sim and Não to validate the responses. It is also necessary to make the…
-
1
votes1
answer101
viewsA: Constant click using Selenium does not work
The problem is that when you click on "load more" the page makes an ajax request and joins the server response to div main, and the button you clicked on initially gets hidden and the driver can’t…
-
2
votes1
answer332
viewsA: How to format sum() output in Python dataframe
You can format the column using the method apply: df.groupby('Ano')['Vlr Benefícios Concedidos (R$)'].sum().apply(lambda x: "{:,.2f}".format(x)) That shows the following format: 1,646,539.00 To get…
-
1
votes2
answers651
viewsA: Filter column by string specifies
You are using the contains method with the symbol $ what pandas interprets as regex. Try adding regex=false: df_movies_usa = df_movies_usa[df_movies_usa["budget"].str.contains("$", regex=False)]…
-
0
votes1
answer848
viewsA: Get value from an Excel cell with Openpyxl (Python)
Using the parameter data_only when opening the Workbook: wb = openpyxl.load_workbook(filename, data_only=True)
-
0
votes1
answer2820
viewsA: Control new Google Chrome tab with Selenium VBA
You can do that with bot.SwitchToWindowByTitle "Title" 'Substitui pelo título exato da nova janela Or if you’ve only opened this new window bot.SwitchToNextWindow EDIT: Here is a simple test to…
-
1
votes2
answers94
viewsA: Program to remove ONLY a copy of duplicate values from a list
If you wanted to remove only 1 copy of each duplicated element, you can use one set and check whether you have "seen" this value or not: def rem(lista): seen = set([]) for i, x in enumerate(lista):…
-
2
votes2
answers75
viewsA: Counting the number of executed operations over the same input for a recursive call
The variable cont is defined as global, but you must initialize it beforehand: def power(base,expoente): global cont cont = 0 if base == 1: return 1 elif expoente == 0: return 1 else: cont +=1…
-
0
votes1
answer128
viewsA: Selenium Basic Python
The problem is that by using the method window.open() the browser opens a new window, so you have to instruct your webdriver to shift the focus to this new window: browser =…
-
1
votes1
answer42
viewsA: How can I timeout an attempt to connect to SQL Server using sqlalchemy?
To SQL Server the correct parameter is Remote Query Timeout create_engine(db_url, connect_args={'Remote Query Timeout': 1})
-
4
votes1
answer3450
viewsA: How to read an excel table in pandas by skipping the first lines without losing information?
A simple way around this problem is by using the function read_excel of pandas, passing the parameter skiprows with the number of rows you want to ignore before the table starts in the excel sheet:…
-
7
votes2
answers361
viewsA: How to create an array with value one?
Can you replicate the numpy.ones, for example using: n = 10 # tamanho do array arr = [1] * n #[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
-
0
votes2
answers239
views -
0
votes1
answer241
viewsA: Allow access to the Chrome Filesystem API with Selenium using Python
This is a Chrome security measure when a website tries to use Chrome Filesystem API. If you have full confidence in the website you are accessing, you can bypass that pop-up by starting Chrome with…
-
2
votes1
answer62
viewsA: Minimum value of a list within another python list
Yes, it is possible to use the internal function min, specifying the comparison key (in this case the first element of each sequence): import numpy as np lista=[] lista.append([0.21, np.array([0.5,…
-
1
votes1
answer36
viewsA: Vector does not print completely - Python, Opencv
Use numpy.set_printoptions at the beginning of your script: import sys import numpy as np np.set_printoptions(threshold=sys.maxsize)…
-
0
votes2
answers507
viewsA: Change List with a python function
For this, it is necessary to change the value of the variable mágicos when calling the function nomes_dos_magicos. Here I use the function enumerate to access the list entry when we are doing the…