-1

I have dataframe with two columns with several values,devided by space:

first_column             second_column
Arkhangelsk P BP -       2.4 3.0 4.8 22.2
Koryazhma N - -          1.5 0.5 5.0 5.8

I need to devide tables in 8 columns:

0           1 2  3 4   5   6   7
Arkhangelsk P BP - 2.4 3.0 4.8 22.2
Koryazhma   N -  - 1.5 0.5 5.0 5.8

How should I solve this problem?

2 Answers2

2

try:

d1 = df['first_column'].str.split(' ', expand=True)
d2 = df['second_column'].str.split(' ', expand=True)
d2.columns = d1.columns + d1.shape[1]
res = pd.concat([d1,d2],axis=1)

res:

0 1 2 3 4 5 6 7
0 Arkhangelsk P BP - 2.4 3.0 4.8 22.2
1 Koryazhma N - - 1.5 0.5 5.0 5.8
Pygirl
  • 12,969
  • 5
  • 30
  • 43
0

Are you importing this data from a csv? Because it seems you could use a sep = " " in the argument section of your pd.read_csv.