简体   繁体   中英

How do I append dataframes/ lenghts of dataframe to a list in a loop in Python

Okay so i have a list of dataframes.

  1. Df1_results
  2. Df2_results
  3. Df3_results

I want to know what dataframes has the most columns and how many columns that is.

So my plan to figure this out was to create a list of lenght of all dataframes then scan list for largest value.

So i wanted a list like size = [ 5, 4, 7]

print('This length')
print(len(df2_results))

I get length 4

size=[]
for i in range(2):    
    print('this is ')
    print("df" + str(i+1) + "_results")
    size.append(len("df" + str(i+1) + "_results"))
size # the list with the new items.
print('*************')
print(size)
print(max(size))

Here i get the length of the string which is 11. Ha. What is a better way to do this? How do I append the dataframes to alist in a loop? How can i get the length of that dataframe when its in a loop?

Later on i might have 10 dataframes .SO i do not want to say say df1_results. i want to be able to say df+i+ _results.

Let Data_list be the list of DataFrames:

Data_list=[Df1_results,Df2_results,Df3_results,...]
[len(data) for data in Data_list]

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM