row

Merging multiple rows in a column into single row with python

Merging multiple rows in a column into single row with python Question: I wanted to merge every four rows in a column into a single row in the next column. For the following dataframe, it will convert 16 rows to 4 rows where each row contains values. df = pd.DataFrame({ ‘A1’: [1,0,0,0,1,1,0,0,1,0,0,0,1,1,1,0]}) output should be, …

Total answers: 1

How to delete just some rows in a dataframe according with some fields condition in Python?

How to delete just some rows in a dataframe according with some fields condition in Python? Question: I need to keep just the first row of a dataframe for each group of values in a ordered column. I need to transform this (first column is ordered by name): a = [[1,’a’],[1,’c’],[1,’b’],[2,’c’],[2,’b’],[2,’a’],[3,’d’]] into this (just the …

Total answers: 1

How do I find the max value in only specific columns in a row?

How do I find the max value in only specific columns in a row? Question: If this was my dataframe a b c 12 5 0.1 9 7 8 1.1 2 12.9 I can use the following code to get the max values in each row… (12) (9) (12.9) df = df.max(axis=1) But I don’t …

Total answers: 1

Pandas create dataframe from one row

Pandas create dataframe from one row Question: Let us say i have some dataframe df and I want to create a new dataframe new_df with n rows each being the same as row idx from df. Is there way to do this in fewer lines compared to: import pandas as pd df = pd.DataFrame() new_df …

Total answers: 2

Getting row sums for specific columns – Python

Getting row sums for specific columns – Python Question: I created a simple dataset df with three columns, Area, Year_2010, Year_2020. The related code: # Import pandas library import pandas as pd # initialize list of lists data = [[‘Netherlands’, 100, 200], [‘Belgium’, 15, 80], [‘Germany’, 125, 300]] # Create the pandas DataFrame df = …

Total answers: 2

fastest way too fill a rows that contain all zeros

fastest way too fill a rows that contain all zeros Question: what is the fastest way to fill every row in 2d array that contains all zeros with different value. Only the rows that all contain Zero.. the only idea I have is a loop and using np.all() to check every row array([[2, 6, 9, …

Total answers: 2

How to launch a conditinated selection of dataframe's row with mixed values

How to launch a conditinated selection of dataframe's row with mixed values Question: I am trying to use the conditioned selection of interested rows/columns into the followng dataset: import pandas as pd already_read = [("Il nome della rosa","Umberto Eco", 1980), ("L’amore che ti meriti","Daria Bignardi", 2014), ("Memorie dal sottsuolo", " Fëdor Dostoevskij", 1864), ("Oblomov", "Ivan …

Total answers: 1