1

I create a small dataframe by these lines:

import pandas as pd
 
my_funds = [1, 2, 5, 7, 9, 11]
my_time = ['2020-01', '2019-12', '2019-11', '2019-10', '2019-09', '2019-08']
df = pd.DataFrame({'TIME': my_time, 'FUNDS':my_funds})

df

The output is then:

    TIME    FUNDS
0   2020-01     1
1   2019-12     2
2   2019-11     5
3   2019-10     7
4   2019-09     9
5   2019-08     11

Would it be possible to modify the code in order to create the dataframe without an index ? I was even not able... So, thanks for any hint.

1 Answer 1

5

A Pandas DataFrame needs an index, but you can set it to an existing column. If all your TIME entries are unique, you can do

import pandas as pd
 
my_funds = [1, 2, 5, 7, 9, 11]
my_time = ['2020-01', '2019-12', '2019-11', '2019-10', '2019-09', '2019-08']
df = pd.DataFrame({'FUNDS': my_funds}, index=my_time)

df

gives you

         FUNDS
2020-01      1
2019-12      2
2019-11      5
2019-10      7
2019-09      9
2019-08     11
Sign up to request clarification or add additional context in comments.

1 Comment

OK. That's why I couldn't... Thanks

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.