Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- ''' A script that converts user input into a dataframe. Writren by Collins'''
- num_columns = int(input('Enter number of columns '))
- values_container = [list() for x in range(num_columns)]
- name_of_columns = [str(input('Enter name of column' + ' ' + str(x) + ' ')) for x in range(num_columns)]
- print("!!!NB Enter a value for the first column then press the enter key to enter more values for the first column. Enter 'q' when done with a column to enter the values of the subsequent columns\nNote all columns must have the same length and value inputs must be terminated with 'q'\n")
- for x in range(num_columns):
- while True:
- value = input('Enter value ')
- if value == 'q':
- break
- values_container[x].append(value)
- zipped = zip(name_of_columns, values_container)
- dic ={ k:v for k,v in zipped}
- try:
- df = pd.DataFrame(dic)
- print(df)
- except Exception as e:
- print(str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement