4

I am trying to get the values from my list and store them into a dataframe

while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
        contains1 = get_rank[rank]
        rank += 1
        rank_list = [rank for rank in contains1]
        df = pd.DataFrame({'A':rank_list[0]},index = [0])
        print(df)

My rank_listoutputs:

[1]
[2]
[3]

My rank_list[0] outputs:

1
2
3

My current output:

   A
0  1
   A
0  2
   A
0  3

My desired output:

   A
0  1
1  2
2  3

2 Answers 2

2

I believe you can append first value of contains1 to list and then out of loop create DataFrame by contructor:

L = []
while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
        rank = get_rank[rank]
        summoner_name = get_summoner_name[rank]
        tier = get_tier[rank]
        lp = get_lp[rank]
        wr = get_wr[rank]
        d = {'rank':rank,
             'summoner_name':summoner_name,
             'tier':tier,
             'lp':lp,
             'wr':wr}

        L.append(d)

df = pd.DataFrame(L)
print(df)
Sign up to request clarification or add additional context in comments.

2 Comments

I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= [],[],[],[],[]
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
0

df = pd.DataFrame(rank_list[0], columns=['A'])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.