Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

string split in pandas

train[['deck', 'num','side']] = train['Cabin'].str.split('/', expand=True)
Comment

split a pd dataframe

In [255]: df = pd.DataFrame(np.random.rand(5, 6), columns=list('abcdef'))

In [256]: df
Out[256]:
          a         b         c         d         e         f
0  0.823638  0.767999  0.460358  0.034578  0.592420  0.776803
1  0.344320  0.754412  0.274944  0.545039  0.031752  0.784564
2  0.238826  0.610893  0.861127  0.189441  0.294646  0.557034
3  0.478562  0.571750  0.116209  0.534039  0.869545  0.855520
4  0.130601  0.678583  0.157052  0.899672  0.093976  0.268974

In [257]: dfs = np.split(df, [4], axis=1)

In [258]: dfs[0]
Out[258]:
          a         b         c         d
0  0.823638  0.767999  0.460358  0.034578
1  0.344320  0.754412  0.274944  0.545039
2  0.238826  0.610893  0.861127  0.189441
3  0.478562  0.571750  0.116209  0.534039
4  0.130601  0.678583  0.157052  0.899672

In [259]: dfs[1]
Out[259]:
          e         f
0  0.592420  0.776803
1  0.031752  0.784564
2  0.294646  0.557034
3  0.869545  0.855520
4  0.093976  0.268974
Comment

PREVIOUS NEXT
Code Example
Python :: open file in python 
Python :: webpage with aiohttp 
Python :: join list of string into a single string with comma 
Python :: Generate hashed passwords for ansible 
Python :: torch.nan_to_num 
Python :: python list pop 
Python :: what is modulus in python 
Python :: DIF_GCD solution 
Python :: winsound python 
Python :: python how to end while loop 
Python :: pypdf2 advanced tutorial 
Python :: jupyter notebook bold text 
Python :: how to make a new column with explode pyspark 
Python :: how to put space in between list item in python 
Python :: django set default value for model not form 
Python :: update django model with dict 
Python :: how to split from a specific charecter to the end of the string in python 
Python :: mac big sur and python3 problems 
Python :: python range() float 
Python :: reverse range python 
Python :: how to start coding in python 
Python :: add columns not in place 
Python :: python dictionary print key value ascending order 
Python :: get maximum value index after groupby 
Python :: python booleans 
Python :: examples of function in python 
Python :: librosa python 
Python :: amazon redshift 
Python :: python dynamic variable name 
Python :: char list python 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =