0

So I uploaded a data from pd.read_table:

df = pd.read_table('Test_Data.txt', delim_whitespace=True, names=('A', 'B'))
    

and the data is:

    A                                                   B
0   AAABBABAABBAAABBBBAABBBABAAABAAAAABBBABBBAAABB...   True
1   AABAABABBBABAAAAABAAABBAABAABBABABBAAABABBBBAB...   True
2   BAAABBBBABABABBBABBAAABAAAAAAABBBBAABABABBBAAB...   True
3   BAABBABBABBAAAABABBBAAAAAAAABAAABBAAAABBAABBAA...   True
4   ABBABBBABBAABAABABBAAABAAAAABABABAABBAABBBAABA...   True

Column A is 100 alphabets. I want to split each in separate columns. I want to have 100 columns of these alphabets and column B as it is. How must I do that?

Thank you!

Umair Nasir
  • 43
  • 1
  • 8
  • Related Question:https://stackoverflow.com/questions/61848671/how-to-convert-strings-in-a-pandas-dataframe-to-a-list-or-an-array-of-characters – Geneva Mar 22 '21 at 12:38

2 Answers2

0

You can use fixed width text to column converting option.

Data > Text to Column >

Excel will let you put pointer where you want the separation to applied.enter image description here

uspinar
  • 595
  • 5
  • 5
0
# for example        
df = pd.DataFrame({"A": ["ABB"]*5, "B": [True]*5})
print(df)

     A     B
0  ABB  True
1  ABB  True
2  ABB  True
3  ABB  True
4  ABB  True

# split string
df["A"] = df["A"].apply(list)
print(df)

           A     B
0  [A, B, B]  True
1  [A, B, B]  True
2  [A, B, B]  True
3  [A, B, B]  True
4  [A, B, B]  True

# new columns' names, here is 3, you could set 100
col_names = list(range(3))
df = pd.concat([df['A'].apply(pd.Series, index=col_names), df["B"]], axis=1)
print(df)


   0  1  2     B
0  A  B  B  True
1  A  B  B  True
2  A  B  B  True
3  A  B  B  True
4  A  B  B  True
Geneva
  • 156
  • 2