Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Difference of two columns in Pandas dataframe
#1
Hi I tring to get two columns from Excel and parse to a DataFrame, after I need subtract this columns.

        
    ndf = xw.Range('AI1:AJ' + str(len(last_row))).options(pd.DataFrame).value

    #Error in this line below
    ndf['VC-BC'] = ndf['VC'] - ndf['BC']
    
    #xw.Range("BH1").options(index=False).value = ndf

    print(ndf.head(20))
After run code error appear
Error:
C:\Users\alexandre.goncalves>C:/Users/alexandre.goncalves/AppData/Local/Programs /Python/Python38-32/python.exe c:/Users/zinho/Downloads/projetos/f at_vfour.py Traceback (most recent call last): File "C:\Users\zinho\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexes\base.py", line 2646, in get_loc return self._engine.get_loc(key) File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 1618, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 1626, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'VC' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:/Users/zinho/Downloads/projetos/fat_vfour.py", line 90, in <module> ndf['VC-BC'] = ndf['VC'] - ndf['BC'] File "C:\Users\zinho\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\frame.py", line 2800, in __getitem__ indexer = self.columns.get_loc(key) File "C:\Users\zinho\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexes\base.py", line 2648, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 1618, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 1626, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'VC'
If try show my new dataframe display like this.
Output:
BC VC 1845.60 0.00 963.72 0.00 1898.00 0.00 15.43 5.56 8.07 2.91 4.99 1.79 41.18 14.75 34.14 12.30 77.32 21.65 107.28 107.28 7.00 2.51 18.50 6.63 6.88 2.47 19.39 6.95 27.96 10.08 51.55 14.43 26.86 9.62 108.02 38.93 98.10 35.15 108.85 39.23
Quote
#2
Hi any help?

this is my cross-post
https://stackoverflow.com/questions/6242...-dataframe
Quote
#3
My question is solved now, thank you
I miss this
ndf = xw.Range('AI1:AJ' + str(len(last_row))).options(pd.DataFrame).value
Would be this
ndf = xw.Range('AI1:AJ' + str(len(last_row))).options(pd.DataFrame, index=False).value
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Pandas DataFrame not updating HelpMePlease 2 55 Yesterday, 05:44 PM
Last Post: HelpMePlease
  Pandas DataFrame visual Truman 8 243 Yesterday, 06:11 AM
Last Post: hussainmujtaba
  Pandas DataFrame and unmatched column sritsv19 0 105 Jul-07-2020, 12:52 PM
Last Post: sritsv19
  Pandas DataFrame Concatenate problems Kristenl2784 1 132 Jul-01-2020, 01:28 AM
Last Post: hussainmujtaba
  error bars with dataframe and pandas Hucky 4 383 Apr-27-2020, 02:02 AM
Last Post: Hucky
  Python Pandas DataFrame Help AmericanEagle1989 1 239 Apr-12-2020, 12:37 PM
Last Post: AmericanEagle1989
  How does pyplot know what was plotted by the output of pandas.DataFrame(...).cumprod( codeowl 2 274 Mar-28-2020, 08:27 AM
Last Post: j.crater
  DataFrame: To print a column value which is not null out of 5 columns mani 2 297 Mar-18-2020, 06:07 AM
Last Post: mani
  Ordering of pandas DataFrame new_to_python 5 326 Mar-15-2020, 06:08 PM
Last Post: new_to_python
Question Dividing a single column of dataframe into multiple columns based on char length darpInd 2 310 Mar-14-2020, 09:19 AM
Last Post: scidam

Forum Jump:


Users browsing this thread: 1 Guest(s)