Python Forum
pandas index not updating please help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: pandas index not updating please help (/thread-27469.html)



pandas index not updating please help - bntayfur - Jun-07-2020

I can't get rid of the old index, still shows the old index and the index title is on top of the old one. what might be the reason for it? Thanks :) the data source is: https://github.com/KeithGalli/Pandas-Data-Science-Tasks/tree/master/SalesAnalysis

i downloaded the data and i was watching from tutorial but in the video this problem didn't occur

import pandas as pd
import os

df = pd.read_csv('./Sales_Data/Sales_April_2019.csv')

files = [file for file in os.listdir('./Sales_Data')]

all_months_data = pd.DataFrame()

for file in files:
    df = pd.read_csv('./Sales_Data/'+ file)
    all_months_data = pd.concat([all_months_data,df])
    
all_months_data.head()

all_months_data.to_csv('all_data.csv', index=False)

nan_df = all_data[all_data.isna().any(axis=1)]
nan_df.head()


all_data = all_data.dropna(how='all')
all_data.head()

all_data['Month']= all_data['Order Date'].str[0:2]
all_data.Month=[int(x.strip('/')) if type(x)==str else x for x in all_data.Month]  #In mine it showed the months as 4/ so thats why i had to do it 

all_data['Month'] = all_data['Month'].astype('int32')
all_data.head()


all_data = all_data[all_data['Order Date'].str[0:2] !='Or'] 

all_data = all_data.reset_index(drop=True)  #for some reason the index jumps 0 to 2 even though the info is ordered just like the downloaded the data

all_data.head()