2021年1月27日星期三

How to load list to DataFrame and iterate over iterrows?

I have the following code I wrote:

        df = pandas.DataFrame(temp_data_list)          return [X(first, rest.tolist()) for first, rest in df.iterrows()]  

The temp_data_list is a list of lists for example [['a',1,2,3],['b',3,2,1]]. I want to convert it to DataFrame and iterate over iterrows and for each element, insert the 'a' to be first and the rest should be [1,2,3]. For some reason it inserts 'a' to the rest. How can I make it work?

https://stackoverflow.com/questions/65909577/how-to-load-list-to-dataframe-and-iterate-over-iterrows January 27, 2021 at 05:32AM

没有评论:

发表评论