Combining spreadsheets in python using pandas -


so, have little bit of code i'm trying work combine spreadsheets in python. here (updated/edited) code:

import pandas pd import numpy np import os os.path import basename  df = []  #enter file names via terminal  file1 = raw_input("enter path first file(don't forget include extension (.xlsx windows)):")  file2 = raw_input("enter path second file(don't forget include extension (.xlsx windows)):")   #combine .xlsx files  f in [file1, file2]:     data = pd.read_excel(f, 'sheet1').iloc[:-2]     data.index = [os.path.basename(f)] * len(data)     df.append(data)  #add column includes original file  data.index = [basename(f)] * len(data)  #set path , name of final product file  final = raw_input('where want file, , want name it? format answer such: (c:\path_to_file\name_of_file.xlsx):')  df = pd.concat(df)  df.to_excel(final) 

the test inputs are:

product   inventory price   sold banana    50        $1.00    27 grapes    100       $3.00    68 

and

product        inventory    price   sold oranges        68           $3.00   17 apples         22           $1.50   9 strawberries   245          $4.00   122 

and yet, result is:

                product inventory   price   sold dbtest2.xlsx    oranges 68             3    17 

ideally, final product this:

                product       inventory price   sold dbtest2.xlsx    oranges           68    $3       17 dbtest2.xlsx    apples            22    $1.50    9 dbtest2.xlsx    strawberries      245   $4.00    122 dbtest1.xlsx    banana            50    $1.00    27 dbtest1.xlsx    grapes            100   $3.00    68 

it's taking 1 item second list... why this?


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -