I made a list of a set of dfs:
dflist = [df1, df2, df3, df4]
I want to loop through all the dfs in the list, print the df name, and print the first 2 lines.
In unix it is simple to do what I want:
cat dflist | while read i; do echo $i && head -2 $i; done
Which returns:
US_distribution_of_soybean_aphid_2022.csv
State,Status of Aphis glycines in 2022,Source,
Connecticut,Present,Rutledge (2004),
But in pandas,
for i in dflist:
    print('i')
    print(i.head(2))
returns literal i followed by the desired head(2) results.
i
   Year           Analyte            Class  SortOrder  PercentAcresTreated  \
0  1991          Methomyl        carbamate       2840              0.00125   
1  1991  Methyl parathion  organophosphate       2900              0.01000   
Using:
for i in dflist:
    print(i)
Prints each df in its entirety.
Very frustrating to a newbie trying to understand the python equivalents of commands I use every day. I'm currently working in a jupyter notebook, if that matters.
 
     
     
    