Python Forum
calculate specified column or row mean
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calculate specified column or row mean
#3
My code below:
i
mport glob
import pandas as pd
path =r'D:\Mekala_Backupdata\PythonCodes\InputFiles' # use your path
allFiles = glob.glob(path + "/*.csv")
frame = pd.DataFrame()
list_ = []
for file_ in allFiles:
    df = pd.read_csv(file_,index_col=None, header=0)
#    df = pd.read_csv(file_,index_col=None)
    list_.append(df)
frame = pd.concat(list_)
test=frame.dropna()
my data is stored in test.

My output show below:

Output:
test Out[53]:     AAB   BT     2     5  5.1 0  YUT  HYT  89.0  52.0  3.0 4  YHT   JU  25.0  63.0  2.0 0  YUT  HYT  89.0  52.0  3.0 4  YHT   JU  25.0  63.0  2.0 0  YUT  HYT  89.0  52.0  3.0 4  YHT   JU  25.0  63.0  2.0
but I want to calculate 3rd row mean and 4th row mean.
I tried as below: but it give error.

test.mean([0,3])

Error:
Traceback (most recent call last):   File "<ipython-input-54-e915aed94ad8>", line 1, in <module>     test.mean([0,3])   File "C:\Users\user\Anaconda3\lib\site-packages\pandas\core\generic.py", line 5632, in stat_func     numeric_only=numeric_only)   File "C:\Users\user\Anaconda3\lib\site-packages\pandas\core\frame.py", line 4930, in _reduce     axis = self._get_axis_number(axis)   File "C:\Users\user\Anaconda3\lib\site-packages\pandas\core\generic.py", line 328, in _get_axis_number     axis = self._AXIS_ALIASES.get(axis, axis) TypeError: unhashable type: 'list'
Reply


Messages In This Thread
RE: calculate specified column or row mean - by SriRajesh - May-20-2017, 01:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  iretate over columns in df and calculate euclidean distance with one column in pandas Pit292 0 3,342 May-09-2021, 06:46 PM
Last Post: Pit292

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020