Python Forum

Full Version: how to remove index in df Row?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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'])
(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
(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...