How to set dataframe based on Index Name Column name

0 votes

Jun 29, 2020 in Python by Gaurav
• 120 points

retagged Jun 29, 2020 by Gitika 235 views

1 answer to this question.

0 votes

Hi@Gaurav,

You can use set_index function in pandas. It allows you to set an index according to your requirement. You can use this below code.

import pandas as pd
df= pd.DataFrame({"Day":[1,2,3,4], "Visitors":[200, 100,230,300], "Bounce_Rate":[20,45,60,10]}) 
df.set_index("Day", inplace= True)
Day visitors  Bounce_Rate
1 200 20
2 100 45
3 230 60
4 300 10
answered Jun 29, 2020 by MD
• 95,300 points

Related Questions In Python

0 votes
1 answer

How to set value for particular cell in pandas DataFrame using index?

Why df.xs('C')['x']=10 does not work: df.xs('C') by default, returns a new ...READ MORE

answered Jan 5 in Python by Gitika
• 65,950 points
1,849 views
0 votes
1 answer

How to find index from raw and column in python?

You probably want to use np.ravel_multi_index: import numpy as ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 58,140 points
298 views
0 votes
1 answer

How to find index from raw and column in python?

You probably want to use np.ravel_multi_index: import numpy as ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 58,140 points
371 views
0 votes
1 answer
0 votes
1 answer

How to append dataframe without index?

You have to use the ignore_index option. ...READ MORE

answered Apr 1, 2019 in Python by Robert
5,928 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,423 views
0 votes
1 answer

How to set colume as index in Pandas DataFrame?

Hi@akhtar, You can use set_index function in pandas. ...READ MORE

answered Jun 23, 2020 in Python by MD
• 95,300 points
138 views
0 votes
1 answer

How to delete column from pandas DataFrame?

Hi@akhtar, You can use the del command in ...READ MORE

answered Jun 24, 2020 in Python by MD
• 95,300 points
287 views