Python Forum
Slittping table into Multiple tables by rows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slittping table into Multiple tables by rows
#1
I have a dataframe which have data in it eg:

A B C
1 2 3
4 2 3
D F C
4 5 7

I want the dataframe to split into two different dataframes as below

A B C
1 2 3
4 2 3

and

D F C
4 5 7




Is there any way to do it in python, kindly help.
Reply
#2
(Oct-06-2021, 11:55 AM)drunkenneo Wrote: Is there any way to do it in python, kindly help.
Yes,next time post some working code and what you tried.
Then it show that you put some effort into it,and it easier to get help.
import pandas as pd
from io import StringIO

data = StringIO("""\
A B C
1 2 3
4 2 3
D F C
4 5 7""")

df = pd.read_csv(data, sep=" ")
>>> df
   A  B  C
0  1  2  3
1  4  2  3
2  D  F  C
3  4  5  7
>>> 
>>> df_1 = df.iloc[:2,:]
>>> df_2 = df.iloc[2:,:]
>>> 
>>> df_1
   A  B  C
0  1  2  3
1  4  2  3
>>> 
>>> df_2.columns = df_2.iloc[0] 
>>> df_2 = df_2[1:]
>>> df_2
2  D  F  C
3  4  5  7
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dynamically Add rows to table TommyAutomagically 1 236 Nov-04-2021, 10:59 PM
Last Post: TommyAutomagically
  How to combine multiple rows of strings into one using pandas? shantanu97 1 895 Aug-22-2021, 05:26 AM
Last Post: klllmmm
  Display table field on multiple lines, 'wordwrap' 3python 0 355 Aug-06-2021, 08:17 PM
Last Post: 3python
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 696 May-04-2021, 10:51 PM
Last Post: rhat398
  Load the data from multiple source files to one table amy83 2 919 Apr-27-2021, 12:33 AM
Last Post: Pedroski55
  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
  Python script to summarize excel tables, then output a composite table? i'm a total n surfer349 1 776 Feb-05-2021, 04:37 PM
Last Post: nilamo
  write mariadb table rows query to each file? shams 1 812 Feb-02-2021, 04:10 PM
Last Post: buran

Forum Jump:

User Panel Messages

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