I'm almost a beginner, so I'm afraid I'm saying something wrong, but I'd appreciate it if you could teach me
As shown at the top of the attached image, there are approximately 40000 rows x 1 column with approximately 100-200 pieces of data (the number varies depending on each row).
I would like to convert this into approximately 40,000 rows x 100-200 columns (missing elements are expressed in #N/A, -, etc.) by dividing approximately 100-200 pieces of 0, 1, and 2.
The list() function seemed useful to divide the strings one by one, so I wrote the following code:
import pandas as pd
seg=pd.read_table('segments.txt')
defseg_split(x):
return(list(x))
seg_list = seg ['segments'].apply(seg_split)
print(seg_list)
This creates data like the bottom of the image, which lists each element of the data frame.
I've looked into various things for beginners, but after this, I don't know how to convert them into approximately 40,000 lines x 100-200 columns instead of lists, so I'm having trouble.
In the first place, the arrangements for listing may not be good.
What to do with NaN
is up to your liking.
seg_list=seg['segments'].apply(lambdai:pd.Series([*i]))
© 2025 OneMinuteCode. All rights reserved.