Note that I was having trouble converting a string to a pandas Dataframe. The trigger was a scene where I wanted to handle a file of about 300GB with pandas. It seems impossible with read_csv () directly, so it was good to cut it finely with open () or readline (), but by the way, it was the first time I made a Dataframe from a character string. When I looked it up, I couldn't find anything good.
I tried using numpy's reshape ().
pd.DataFrame(np.array(data.split()).reshape(-1,7))
The image looks like this.
Fortunately, the number of columns was fixed. If the number of lines is not fixed, it seems better to put -1 in the argument of reshape (). The number of columns is also the same. Please let me know if there is another good way.
Recommended Posts