2

I have a list that looks like this:

['2016-01-05', '2017-02-03', '2018-01-25', ['File_2016.csv', 'File_2017.csv', 'File_2018.csv']]

Which is an output of a user entered field, and the partition of the data, where the first set of items ('2016-01-05', '2017-02-03', '2018-01-25') are the user entered fields, and the second set ('File_2016.csv', 'File_2017.csv', 'File_2018.csv') are the corresponding files.

What I'd like to do is create a dataframe that looks like this:

Date             File
2016-01-05      File_2016.csv
2017-02-03      File_2017.csv
2018-01-25      File_2018.csv

My code looks like this:

my_list = [input('enter the start date for file %s: ' % i) for i in list(filenames)]

Where filenames is a list of the Files above, and I append filenames to the list after the above user inputs.

Is there a better way to do this?

Thank you!

1 Answer 1

3

Not sure if this is better than what you've got now, but here's another way of doing it:

df = pd.DataFrame(list(zip(l[:-1], l[-1])), columns=['Date', 'File'])
df
         Date           File
0  2016-01-05  File_2016.csv
1  2017-02-03  File_2017.csv
2  2018-01-25  File_2018.csv
Sign up to request clarification or add additional context in comments.

1 Comment

That is perfect. Thank you!!

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.