Python:使用用户输入的字符串附加数据帧

时间:2017-02-13 05:05:24

标签: python string pandas dataframe

所以我目前正在研究一些代码,到目前为止我还有

numbers=int(raw_input('Enter number of classes you are taking:))
#loop for info for each class
for x in range(numbers):
    data = str(raw_input(Enter class name,teacher,credit hours))
    df={'class name':data[0],'teacher':data[1],'credit hours':data[2]}
    frame=frame.append(df,ignore_index=True)

我似乎无法获取数据框以打印用户输入字符串的第一个值,我做错了什么?

1 个答案:

答案 0 :(得分:0)

frame = []
numbers=int(raw_input('Enter number of classes you are taking:'))
#loop for info for each class
for x in range(numbers):
   data = str(raw_input('Enter classname,teacher,credithours:')).split(',')
   # print(data) # out => [name,teacher,credit hours] 
   df={'class name':data[0],'teacher':data[1],'credit hours':data[2]}
   frame=frame.append(df)
   print(frame)