logo
down
shadow

Rearrange rows of Dataframe alternatively


Rearrange rows of Dataframe alternatively

Content Index :

Rearrange rows of Dataframe alternatively
Tag : python , By : user183275
Date : November 28 2020, 04:01 AM

like below fixes the issue If the size of the subgroups is known, let's call it n, and your DataFrame is chunked with each group following the other, we just need some math:
n=5

df.index = df.index%n + (df.index//n)/(len(df)/n)
df = df.sort_index().reset_index(drop=True)
   col1           col2
0     1  random_string
1    1x  random_string
2    1y  random_string
3     2  random_string
4    2x  random_string
5    2y  random_string
6     3  random_string
7    3x  random_string
8    3y  random_string
9     4  random_string
10   4x  random_string
11   4y  random_string
12    5  random_string
13   5x  random_string
14   5y  random_string

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Python: create a single dataframe by alternatively include rows from two others


Tag : python , By : afarouk
Date : March 29 2020, 07:55 AM
I hope this helps . Suppose I have two pandas of the form: , Try this:
In [501]: pd.concat([df, df1.set_index(df1.index + '_s')]).sort_index()
Out[501]:
                  A          B          C
first     62.184209  39.414005  60.716563
first_s    0.828069   0.762570   0.717368
second    51.508214  94.354199  16.938342
second_s   0.136098   0.991668   0.547499
third     36.081861  39.440953  38.088336
third_s    0.120465   0.546807   0.346949

How to rearrange rows of dataframe according to number array


Tag : r , By : Ambarish Singh
Date : March 29 2020, 07:55 AM
hope this fix your issue I believe you are dealing with the "drop" issue. When R reads a matrix with only a single column, that 2nd dimension (columns) gets "dropped." This can be fixed by adding a simple "drop = FALSE" argument after the dimensions.
Object[Row,Column, drop = FALSE]
x <- matrix(c(1,2,2,1,1,2))
dimnames(x) <- list(c("TGTT", "TGTG", "TGCG", "TGGA", "TCCG", "TCAG"), "TCGA-05-4244-01A-01D-1105-08")
match <- c(1,3,2,6,5,4)
x[match,,drop = F]
     TCGA-05-4244-01A-01D-1105-08
TGTT                            1
TGCG                            2
TGTG                            2
TCAG                            2
TCCG                            1
TGGA                            1

how to rearrange rows in a dataframe based on time sequence


Tag : r , By : Pieter Taelman
Date : March 29 2020, 07:55 AM
To fix this issue I have a data frame dd as follows , Using sqldf library:
sqldf("select * from sample order by Time")
       Time         a b  c
1  10:39:00.064 IST A 8  1
2  10:39:00.165 IST D 3  1
3  10:39:00.265 IST A 9  1
4  10:39:00.366 IST C 9  2
5  10:39:00.466 IST D 5 25
6  10:39:00.566 IST W 8  1
7  10:39:00.665 IST W 6 42
8  10:39:00.765 IST I 5 45
9  10:39:00.866 IST P 4  2
10 10:39:00.967 IST T 9  4
11 10:39:01.067 IST R 7  8
12 10:39:01.168 IST Q 5 68
13 10:39:01.269 IST S 6 59
14 10:39:01.369 IST A 8 35
15 10:39:01.468 IST J 5  7
16 10:39:01.570 IST D 8 66
17 10:39:01.671 IST F 7  5
18 10:39:01.771 IST K 7  5

How to rearrange/reorder the rows and columns in python dataframe?


Tag : python , By : Stephen
Date : December 28 2020, 06:11 AM
I wish this help you SCREEN SHOT OF ACTUAL DATA FRAMEDataframe of 5000 rows and 192 columns , IIUC, can use a loop
pd.DataFrame([df.iloc[:, e:e+3].values.flatten() for e in range(0, 192, 3)])

Rearrange dataframe, every n rows to columns, left to right, top down


Tag : python , By : esimran
Date : March 29 2020, 07:55 AM
it should still fix some issue A list of strings. , Just change the reshape parameter and pass order parameter
df_1 = pd.DataFrame(np.reshape(df.values,(3,5),order='F'))
Related Posts Related QUESTIONS :
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • How to calculate each single element of a numpy array based on conditions
  • How do I change the width of Jupyter notebook's cell's left part?
  • Measure distance between lat/lon coordinates and utm coordinates
  • Installing megam for NLTK on Windows
  • filter dataframe on each value of a samn column have a specific value of another column in Panda\Python
  • Threading with pubsub throwing AssertionError: 'callableObj is not callable' in wxPython
  • Get grouped data from 2 dataframes with condition
  • How can I import all of sklearns regressors
  • How to take all elements except the first k
  • Whats wrong with my iteration list of lists from csv
  • Tensorflow Estimator API save image summary in eval mode
  • How to Pack with PyQt - how to make QFrame/Layout adapt to content
  • How do I get certain Time Range in Python
  • python doubly linked list - insertAfter node
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com