1

Given a list as follows:

['start year: 2019', 'end year: 2021']

How could I split them by : and convert into a dataframe?

start year      end year
  2019            2021

Thanks for your help at advance.

1 Answer 1

3

You can do

df = pd.DataFrame([x.split(':')for x in l ]).set_index(0).T
0 start year end year
1       2019     2021
Sign up to request clarification or add additional context in comments.

1 Comment

May I ask: why the column name row's is 0, index 0 should start with 2019 2021 row, right?

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.