0

I am working on an excel file with multiple sheets, This excel file has some common columns in every sheet and common rows which i want to remove. When I read the excel file, I am getting a dict variable. I tried to get values from the Dict and to store them into the Dataframe. But when I drop the columns from the dataframe something weird is happening they are not getting dropped and the values in the loop and outside the loop the daataframe only has one sheets data.

Below is what I have done.

Retriveing part

import pandas as pd
url1 = 'https:.............xlsx'

dict_url = pd.read_excel (url1,sheet_name = None)

Editing part, this is where i was trying to use drop() on dataframe but its not working

for key in dict_url.keys():
        temp_df = pd.DataFrame(dict_url[key])
        df2 = temp_df.drop(['Unnamed: 3', 'Unnamed: 4'], axis=1)
        df3 = df2.drop([0,1])
        finaldf=  df3.drop(df3.tail(1).index,inplace=True)

if i don't use the for loop and do this instead it works

df = pd.DataFrame()
for key in dict_url.keys():
 
    df = pd.DataFrame(dict_url[key])
    print(df)

df2 = df.drop(['Unnamed: 3', 'Unnamed: 4'], axis=1)
df3 = df2.drop([0,1])
df4 =  df3.drop(df3.tail(1).index,inplace=True)

print(df4)

What is it that i am missing

depp
  • 25
  • 6
  • Try providing an example of the dataframes you are using. But, I have noticed that you have double indentation on the for loop, so it should not work properly – jlb_gouveia Oct 28 '20 at 21:26
  • Oh i actually typed the whole code and by mistake placed double indentation on the for loop. – depp Oct 28 '20 at 21:57
  • Please provide a [mcve], as well as the current and expected output. See [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391). – AMC Oct 28 '20 at 23:03

0 Answers0