Posts by Leonardo Bohac • 413 points
10 posts
-
5
votes6
answers491
viewsA: Optimize code in Python
A one-Liner for you: f = lambda: input('Digite em maiúsculo: ').isupper() and 'Texto Correto!' or f() To execute: f()
-
3
votes1
answer125
viewsA: Easy counting between columns - Python
(in case you want to count the number of equal entries for each possible pair of columns) import pandas as pd import numpy as np Colunas = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] Duplas =…
-
2
votes1
answer517
viewsA: Extract phone number with API in Python pandas
It is usually possible to do operations on Pandas without using the command for, making use of something called "vectorization". See if this works: import numpy as np # separando a extração de cada…
-
1
votes1
answer211
viewsA: Transpose columns to rows in Python data frame
whereas df is your Dataframe: temp = df.groupby('data').cumcount() + 1 df = df.set_index(['data', temp]).unstack().sort_index(1, level=1) df.columns = ['_'.join(map(str,i)) for i in df.columns]…
-
2
votes2
answers778
viewsA: Python pandas: Drop rows with duplicate column and another column with null value
What you did is almost right, it lacked only a small detail in the function duplicated, and conditioning is done together: df2 = df[df.duplicated('Col1', keep=False) & df['Col2'].isnull()] With…
-
1
votes1
answer55
viewsA: Repeat code for the same product group
df.fillna('', inplace=True) while('' in df['CODIGO'].values): df.loc[df['CODIGO'] == '', 'CODIGO'] = df.loc[:, 'CODIGO'].shift(1)
-
1
votes2
answers528
viewsA: Swap String Values from a Dataset to'Float' values
To convert the data type into a Dataframe column (if using Pandas), you can run the command: DF['NomeDaColuna'] = DF['NomeDaColuna'].astype(float) # converte para float, neste caso How you’ll be…
pythonanswered Leonardo Bohac 413 -
1
votes1
answer60
viewsA: XOR operation by filtering my list values in Dataframe columns
To create the XOR column, you can do so: df = pd.DataFrame(np.random.randint(low=0, high=2, size=(5, 5)), columns=['uva', 'pera', 'maca', 'banana', 'melao']) df['XOR maca_banana'] = df['maca'] ^…
-
1
votes2
answers128
viewsA: How to handle an address base
If you have Pandas installed (Pandas is a Python-compatible database library), you can do this with the following code: import pandas as pd Dicionario_BancoDeDados = {'123.456.789-10' : {'CEP':…
pythonanswered Leonardo Bohac 413 -
5
votes4
answers146
viewsQ: Performing functions with and without creating local variables
Despite the simplicity of this question, I could not find an answer to it on the Internet. Is there any structural/performance difference between the two functions defined below? def F(x): Output =…