Python - How to store values from a while loop into a pandas dataframe?
up vote
1
down vote
favorite
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
python arrays python-3.x pandas
add a comment |
up vote
1
down vote
favorite
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
python arrays python-3.x pandas
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
python arrays python-3.x pandas
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
python arrays python-3.x pandas
python arrays python-3.x pandas
asked Nov 10 at 7:10
g_altobelli
877
877
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
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)
I figured this would work but I am trying to make it more readable instead of doing thisrank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
– g_altobelli
Nov 10 at 8:04
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
– jezrael
Nov 10 at 8:11
add a comment |
up vote
0
down vote
df = pd.DataFrame(rank_list[0], columns=['A'])
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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)
I figured this would work but I am trying to make it more readable instead of doing thisrank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
– g_altobelli
Nov 10 at 8:04
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
– jezrael
Nov 10 at 8:11
add a comment |
up vote
1
down vote
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)
I figured this would work but I am trying to make it more readable instead of doing thisrank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
– g_altobelli
Nov 10 at 8:04
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
– jezrael
Nov 10 at 8:11
add a comment |
up vote
1
down vote
up vote
1
down vote
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)
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)
edited Nov 10 at 8:10
answered Nov 10 at 7:18
jezrael
312k21247323
312k21247323
I figured this would work but I am trying to make it more readable instead of doing thisrank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
– g_altobelli
Nov 10 at 8:04
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
– jezrael
Nov 10 at 8:11
add a comment |
I figured this would work but I am trying to make it more readable instead of doing thisrank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
– g_altobelli
Nov 10 at 8:04
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
– jezrael
Nov 10 at 8:11
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
Nov 10 at 8:04
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
Nov 10 at 8:04
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
– jezrael
Nov 10 at 8:11
@g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
– jezrael
Nov 10 at 8:11
add a comment |
up vote
0
down vote
df = pd.DataFrame(rank_list[0], columns=['A'])
add a comment |
up vote
0
down vote
df = pd.DataFrame(rank_list[0], columns=['A'])
add a comment |
up vote
0
down vote
up vote
0
down vote
df = pd.DataFrame(rank_list[0], columns=['A'])
df = pd.DataFrame(rank_list[0], columns=['A'])
answered Nov 10 at 7:37
user3665224
3011316
3011316
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236798%2fpython-how-to-store-values-from-a-while-loop-into-a-pandas-dataframe%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown