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: 249)
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
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 652 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  Trying to understand strings and lists of strings Konstantin23 2 696 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 1,380 Jun-09-2023, 08:42 PM
Last Post: ctrldan
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 797 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  How to combine multiple column values into 1? cubangt 15 2,626 Aug-11-2022, 08:25 PM
Last Post: cubangt
  Splitting strings in list of strings jesse68 3 1,702 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Search multiple CSV files for a string or strings cubangt 7 7,838 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,599 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Slittping table into Multiple tables by rows drunkenneo 1 2,000 Oct-06-2021, 03:17 PM
Last Post: snippsat
  Python Pandas: How do I sumproduct by rows with an if condition? JaneTan 2 5,278 Jul-13-2021, 11:36 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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