Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code working like this. i want this to ask for user input and put it inside pandas dataframe
how many times do you want to input: 2
Input Name: First
Input Age: 12
Input Name: Second
Input Age: 32
['First', 12, 'Second', 32]'  
#this part is my problem, im stuck here on putting a column level 
    0
0  ha
1  12
2  la
3  32




pls help me to make this like this one 

    Name		Age
0	First		12
1	Second 		32


What I have tried:

lst=[]
n=int(input("how many times do you want to input: "))
for i in range (0, n):
    eles = str(input("Input Name: "))
    els = int(input("Input Age: "))
    lst.append(eles)
    lst.append(els)

print(lst)

import pandas as pd
df = pd.DataFrame(lst)
print(df)
Posted
Updated 27-Nov-22 6:39am
v2

1 solution

See Intro to data structures — pandas 1.5.2 documentation[^] for different ways to construct a DataFrame.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900