0

I am attempting to change the index of this dataframe to 'Close Time'

                Open            High             Low           Close              Close Time  
0     19183.87000000  19185.11000000  19170.00000000  19177.47000000 2022-10-17 03:57:59.999                   
1     19177.47000000  19189.30000000  19176.59000000  19185.35000000 2022-10-17 03:58:59.999                   
2     19185.35000000  19191.15000000  19185.33000000  19186.38000000 2022-10-17 03:59:59.999                   
3     19186.38000000  19189.65000000  19169.14000000  19172.65000000 2022-10-17 04:00:59.999                   
4     19173.64000000  19175.69000000  19162.24000000  19167.40000000 2022-10-17 04:01:59.999                   

I have tried

df.set_index('Close Time', inplace=True, drop=True)

which didn't change the dataframe at all so I tried

new_df = df.set_index('Close Time', inplace=True, drop=True)
print(new_df)

output was 'None'

I'm a pandas beginner so I checked the type type(df) and got <class 'pandas.core.frame.DataFrame'>

I'm using pycharm and set_index() is showing 'No Documentation Found'

0

2 Answers 2

1

When you're using inplace=True it will change the dataframe directly without returning the dataframe

So in your case it's either:

new_df = df.set_index('Close Time', drop=True)
print(new_df)

or

df.set_index('Close Time', inplace=True, drop=True)
print(df)

Can you show the output of the second one, since you said it didn't change it?

Sign up to request clarification or add additional context in comments.

Comments

0

If you are reading from a file, use .read_csv(filename) to read the data frame. By the way, ignore the drop=True in your code as it is the default setting. So, it works just fine:

df.set_index('Close Time', inplace=True)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.