Python Forum
Populate the new lists by looping over the original lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Populate the new lists by looping over the original lists
#1
have dataframe gapminder and every column is organized as separate list using code as below:

country = df.country.to_list()
continent = df.continent.to_list()
year = df.year.to_list()
I have created an empty list country_1990 and I want to populate it with data from year 1990 by looping over the original list country

How can I perform this task? Tried this:

for i in range(len(df.country)): 
        if df.loc[df['year']== 1990 :
            country_1990.append(df.country[i])
print(country_1990)
to check at each iteration of the loop if the associated record is from 1990 but not working
Thx
Reply
#2
your code does not have as many ] as it has [ so they are out of balance.  i cannot figure out just what you are trying to do.  can you fix it and try post it again (with tags this time).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Heart Sets cannot contain lists, how to circumvent? meijeru 3 87 Mar-18-2026, 05:13 AM
Last Post: Pedroski55
  Help with Lists Nevvieboy 8 1,173 Oct-20-2025, 07:59 AM
Last Post: Blablabla
  Extracting parts of paragraphs from word documents using python-docx library & lists Den0st 1 28,357 Oct-08-2025, 05:56 AM
Last Post: OtiliaGen
  Appending lists into lists from function is not working for me BoredBannana 2 2,112 Oct-25-2024, 05:18 PM
Last Post: deanhystad
  Nested Lists & Dictionaries Hudjefa 5 2,259 Sep-23-2024, 08:20 PM
Last Post: DeaD_EyE
Sad The issue with compare 2D lists przonak007 18 5,363 Jul-17-2024, 07:31 AM
Last Post: Pedroski55
  Compare lists w_i_k_i_d 6 2,496 May-23-2024, 07:23 PM
Last Post: deanhystad
Question Using Lists as Dictionary Values bfallert 8 3,938 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  problem with print lists MarekGwozdz 4 2,445 Dec-15-2023, 09:13 AM
Last Post: Pedroski55
  python convert multiple files to multiple lists MCL169 6 4,618 Nov-25-2023, 05:31 AM
Last Post: Iqratech

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020