Python Forum
how to remove index in df Row?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to remove index in df Row?
#1
I am trying to split a string text by ",&: " and put it back to newly created df with columns name
but facing a problem, the result overwrite/ignored my df columns name and return columns instead.
dfA=pd.DataFrame(columns=["NAME","REMARK","SPLITIND","INFO","AREA"])
dfA=dfB["SETUP"].str.split(',|:',expand=True)
how to remove index in df Row?
Reply
#2
If I understood you correctly, the sample below could be useful for you:

import pandas as pd
dfb = pd.DataFrame({'setup': ['1,2,3,4', '4,5,6,7', '6,7,8,4']})
dfa = pd.DataFrame(dfb['setup'].str.split(',').values.tolist(), columns=['one', 'two', 'three', 'four'])
Reply
#3
(Apr-27-2018, 07:40 AM)scidam Wrote: If I understood you correctly, the sample below could be useful for you:
import pandas as pd dfb = pd.DataFrame({'setup': ['1,2,3,4', '4,5,6,7', '6,7,8,4']}) dfa = pd.DataFrame(dfb['setup'].str.split(',').values.tolist(), columns=['one', 'two', 'three', 'four']) 
your solution is good, but actually I wanted to remove index row, because it return index number 0,1,2,3.... by default
Reply
#4
(May-04-2018, 07:16 AM)issac_n Wrote: I wanted to remove index row, because it return index number 0,1,2,3.... by default

>>> x = pd.DataFrame({'x':[7,8,9], 'y':[4,5,6]})
>>> x
   x  y
0  7  4
1  8  5
2  9  6
So, do you want to remove 0, 1, 2 in the example above? If so, you need to know that pandas series and data frames always have an index...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Getting Index Error - list index out of range krishna 2 2,613 Jan-09-2021, 08:29 AM
Last Post: buran
  Getting Index Error - list index out of range RahulSingh 2 6,157 Feb-03-2020, 07:17 AM
Last Post: RahulSingh

Forum Jump:

User Panel Messages

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