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
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 701 Aug-09-2023, 05:51 PM
Last Post: Calab
  python script for inserting rows into hbase table lravikumarvsp 7 7,000 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
  extract table from multiple pages sshree43 8 5,080 Dec-12-2022, 10:34 AM
Last Post: arvin
  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
  Dynamically Add rows to table TommyAutomagically 1 2,061 Nov-04-2021, 10:59 PM
Last Post: TommyAutomagically
  How to combine multiple rows of strings into one using pandas? shantanu97 1 3,096 Aug-22-2021, 05:26 AM
Last Post: klllmmm
  Display table field on multiple lines, 'wordwrap' 3python 0 1,747 Aug-06-2021, 08:17 PM
Last Post: 3python
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,080 May-04-2021, 10:51 PM
Last Post: rhat398
  Load the data from multiple source files to one table amy83 2 2,521 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 6,957 Mar-02-2021, 01:54 AM
Last Post: Jeremy7

Forum Jump:

User Panel Messages

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