0

hello everyone I have two data sets I'm trying to first clean up and then combine into one data frame for exporting. My data is scrapped from a webpage and this is the result called df1 and df2. my first problem is the data keeps coming back with the first column I have labeled (blank) is just an empty cell with nothing in it and 0 both of which are useless and I want to remove.

EDIT: thanks to @richardec This worked for the first df1 removing the blank and 0 altogether. But didn't solve it for df2.

df1= df1.set_index('Item') 

What i had to do was

df2.to_excel('df2.xlsx', index=False)

and it worked for df2

Orgininal Code:

df1 = (Blank)   Item         Quantity      Date 
      0       disposable cups   7000        07/01/22

df2= (blank)  Order Number
       0      A-21-897274 

What I've tried:

 df1.reset_index()
 df1.drop_na(inplace=True)
 df1 = df1.drop(0, axis=1)

none of these have worked for me. Any help cleaning up this data would be greatly appreciated so that when its brought to excel there isn't a blank space and 0 listed.

seanofdead
  • 99
  • 1
  • 6
  • 1
    You can't get rid of the index. You can set another column to be the index, e.g., `df = df.set_index('Item')`, but you can't eliminate it entirely. –  Mar 20 '22 at 23:26
  • so `df1= df1.set_index('Item')` and `df2=df2.set_index(Order Number)` ? – seanofdead Mar 20 '22 at 23:30
  • Yes, something like that should work. But, I think you should do that *after* you merge and process the dataframes, etc., because changing the indexes like that can cause horrible problems... –  Mar 20 '22 at 23:32
  • I tried the `df2=df2.set_index(Order Number)` and the results where shifted somehow. So the print out in terms of excel `a1= blank a2= order number a3= A-21-897274` – seanofdead Mar 20 '22 at 23:36
  • but oddly enough `df1= df1.set_index('Item')` worked perfectly. – seanofdead Mar 20 '22 at 23:45
  • 1
    Does this answer your question? https://stackoverflow.com/questions/21256013/pandas-dataframe-hide-index-functionality –  Mar 21 '22 at 00:03

0 Answers0