Python Forum
How to combine multiple rows of strings into one using pandas?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to combine multiple rows of strings into one using pandas?
#1
I have a DataFrame with multiple rows. Is there any way in which they can be combined to form one rows? Marked with Yellow Colours. All I want to combine that into one row.
Remember that I wanted to ignore the empty rows when you combine.
See the output section of attached image("Problem. jpg"). I want my output looks like this.
But I cannot find logic to this problem. Any idea?
Attach File.

Attached Files

Thumbnail(s)
   

.csv   Test.csv (Size: 259 bytes / Downloads: 66)
Reply
#2
Hope you can see such output from this code

import re

for i in range(Data_list.shape[0]): #iterate over rows
    for j in range(Data_list.shape[1]): #iterate over columns
        if ((i ==0) & (j ==0)):
            heading = re.sub(r'[^\x00-\x7f]',r'', Data_list.at[i, j]) #get cell value
            print(heading, end="\n")
        else:
            if pd.notnull(Data_list.at[i, j]):
                data = re.sub(r'[^\x00-\x7f]',r'', Data_list.at[i, j]) #get cell value
                print(data, end=", ")
Output:
Comments & Equip. Transfers Drilling good ground all shift, 2 x Gyro Surveys, Mixing muds to condition the hole, Driller travelled home for shift change at end of shift, Equipment onsite=,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Slittping table into Multiple tables by rows drunkenneo 1 335 Oct-06-2021, 03:17 PM
Last Post: snippsat
  Python Pandas: How do I sumproduct by rows with an if condition? JaneTan 2 996 Jul-13-2021, 11:36 AM
Last Post: jefsummers
  Partial Matching Rows In Pandas DataFrame Query eddywinch82 1 607 Jul-08-2021, 06:32 PM
Last Post: eddywinch82
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 696 May-04-2021, 10:51 PM
Last Post: rhat398
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 2,390 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 2,368 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  How to filter out Column data From Multiple rows data? firaki12345 10 1,727 Feb-06-2021, 04:54 AM
Last Post: buran
  Inserting multiple rows in a single request. swaroop 2 842 Jan-11-2021, 01:34 PM
Last Post: swaroop
  how to combine rows to a column base on ids zhujp98 0 537 Nov-03-2020, 04:10 PM
Last Post: zhujp98
  How to diff pandas rows and modify column value Mekala 1 720 Sep-18-2020, 12:38 PM
Last Post: Mekala

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020