Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Example 1: Reset Index & Drop Old Index pandas

import pandas as pd

#define DataFrame
df = pd.DataFrame({'points': [25, 12, 15, 14, 19, 23, 25, 29],
                   'assists': [5, 7, 7, 9, 12, 9, 9, 4],
                   'rebounds': [11, 8, 10, 6, 6, 5, 9, 12]},
                   index=[0, 4, 3, 5, 2, 1, 7, 6])

#view DataFrame
print(df)

   points  assists  rebounds
0      25        5        11
4      12        7         8
3      15        7        10
5      14        9         6
2      19       12         6
1      23        9         5
7      25        9         9
6      29        4        12
Comment

Reset Index & Retain Old Index as Column in pandas

import pandas as pd

#define DataFrame
df = pd.DataFrame({'points': [25, 12, 15, 14, 19, 23, 25, 29],
                   'assists': [5, 7, 7, 9, 12, 9, 9, 4],
                   'rebounds': [11, 8, 10, 6, 6, 5, 9, 12]},
                   index=['A', 'C', 'D', 'B', 'E', 'G', 'F', 'H'])

#view DataFrame
print(df)

   points  assists  rebounds
A      25        5        11
C      12        7         8
D      15        7        10
B      14        9         6
E      19       12         6
G      23        9         5
F      25        9         9
H      29        4        12
Comment

PREVIOUS NEXT
Code Example
Python :: 2--2 in python prints? 
Python :: matplotlib keyboard event 
Python :: replace NaN value in pandas data frame 
Python :: tadjust margines automatically matplotlib 
Python :: pd column to one hot vector 
Python :: python assertEqual tuple list 
Python :: python find in string 
Python :: WARNING: Ignoring invalid distribution -ip (c:python310libsite-packages) 
Python :: metodo estatico de python 
Python :: python sleeping with a varible 
Python :: wrds in python 
Python :: delete everything from list that matches string 
Python :: Second step creating python project 
Python :: pomodoro timer in python 
Python :: matplotlib smooth loss curves 
Python :: daemon in os 
Python :: Update only values in python 
Python :: how to load csv file pyspark in anaconda 
Python :: how to solve spacy no model en 
Python :: menampilkan data dalam range tertentu di python 
Python :: django admin make column link 
Python :: python remove title from name 
Python :: How to download images from the OIDv4 in Anaconda Promt 
Python :: convert darkflow yolov3 tensorflow lite 
Python :: pycharm writing issue 
Python :: how to load multiple list of dictionary values which is stored in python file and load into another python file in python over loop 
Python :: spyder - identation 
Python :: python selenium not returning correct source 
Python :: vehari weather 
Python :: fibonacci series recursive python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =