0

My code:

coins = ['dashcoin','litecoin','dogecoin','nxt']
pd.DataFrame(columns=['timestamp',coins])

I need a header with 5 different values, but my method create two, the first time stamp then the second 'coins' all in one header.

timestamp     dashcoin   litecoin   dogecoin    nxt

How can we separate like pd.DataFrame(columns=coins)

1 Answer 1

1

You could wrap your string to list with [] and then use + operator with your coins:

res = pd.DataFrame(columns=[['timestamp'] + coins])

In [148]: res
Out[148]:
Empty DataFrame
Columns: [timestamp, dashcoin, litecoin, dogecoin, nxt]
Index: []

Or with one list:

new_coins = ['timestamp'] + coins
res = pd.DataFrame(columns=new_coins)

In [152]: res
Out[152]:
Empty DataFrame
Columns: [timestamp, dashcoin, litecoin, dogecoin, nxt]
Index: []
Sign up to request clarification or add additional context in comments.

Comments

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.