Posts: 55
Threads: 24
Joined: Nov 2017
Apr-26-2018, 07:14 AM
(This post was last modified: Apr-26-2018, 07:14 AM by issac_n.)
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?
Posts: 817
Threads: 1
Joined: Mar 2018
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'])
Posts: 55
Threads: 24
Joined: Nov 2017
(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
Posts: 817
Threads: 1
Joined: Mar 2018
(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...
|