-1
check1= [check1[col].fillna('1111-1111' ) for col in check1]
check1 = pd.DataFrame(check1).add_prefix('col_')

    col_col_0   col_col_1   col_col_2   col_col_3   col_col_4   col_col_5   col_col_6   col_col_7   col_col_8   col_col_9   col_col_10  col_col_11  col_col_12  col_col_13
0   1-2 6-7 1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
1   3-4 51-57   71-72   91-94   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
2   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
3   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
4   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
116 5-7 40-41   65-67   70-74   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
117 1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
118 1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
119 1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111
120 1-5 1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111   1111-1111

Now i want to split the complete dataframe like below for all columns. Please help

enter image description here

check2 = [check1[col].str.split('-', expand=True) for col in check1] im using this but its not working for all columns.

G. Anderson
  • 5,815
  • 2
  • 14
  • 21
  • Your input sample is confusing. Please have a look at [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and [edit] to only include a _representative sample_ of your input and expected output as text that we can run, to make a [mcve] – G. Anderson Jun 28 '21 at 23:22

1 Answers1

1

The problem is your check2 is returning a list, not a DataFrame

You can use this:

col_col_0   col_col_1
0   1-1     7-7
1   2-2     8-8
2   3-3     9-9
3   4-4     10-10
4   5-5     11-11
5   6-6     12-12

df_merge = pd.DataFrame()
for col in df:
    df_col = df[col].str.split('-', expand=True)
    df_merge = df_merge.append(df_col)

OUTPUT

    0   1
0   1   1
1   2   2
2   3   3
3   4   4
4   5   5
5   6   6
0   7   7
1   8   8
2   9   9
3   10  10
4   11  11
5   12  12
Shubham Periwal
  • 2,198
  • 2
  • 8
  • 26