'How can I use pandas to read a text file and split the joined characters to different columns in a dataframe?

An example of a Line in my text file: Hellothisismyquestion56464

I want to my Data frame to look like this:

C1 C2 C3 C4 C5 C6
Hello this is my question 56464


Solution 1:[1]

There are a variety of methods available to read a text file using pandas as mentioned here.

However, you need to specify a delimiter or a separator to achieve what you are trying to do. Following is an example code snippet of the same:

import pandas as pd
  
# read text file into pandas DataFrame and create header with names
df = pd.read_csv("gfg.txt", sep=" ", header=None, 
                 names=["Team1", "Team2"])
  
# display DataFrame
print(df)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1