I want to eliminate each element in the python pandas data frame from the list.

Asked 1 years ago, Updated 1 years ago, 252 views

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.Attachment

python pandas

2022-10-04 01:01

1 Answers

What to do with NaN is up to your liking.

seg_list=seg['segments'].apply(lambdai:pd.Series([*i]))


2022-10-04 01:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.