英文:
How to calculate mean of rows from excel spreadsheet instead of columns?
问题
我不知道如何计算所有行的均值,而不是所有列的均值。我正在使用一个包含超过8000行的大型预制数据集,并希望找到每行的均值,以便在一个图表上将它们全部表示出来。我不想交换行和列,除非那是我的唯一选择。
xlsx = pd.ExcelFile(r'/Users/Admin/file.xlsx')
df1 = pd.read_excel(xlsx, 'Sheet1')
df2 = pd.read_excel(xlsx, 'Sheet2')
medians = df2.median(numeric_only=True)
means = df2.mean(numeric_only=True)
英文:
I have no idea how to calculate the means of all rows rather than all columns. I am using a large premade dataset with over 8000 rows and would like to find the mean of each in order to graph them all on one chart. I would not like to switch the rows to columns and vice versa unless that is my only option.
xlsx = pd.ExcelFile(r'/Users/Admin/file.xlsx')
df1 = pd.read_excel(xlsx, 'Sheet1')
df2 = pd.read_excel(xlsx, 'Sheet2')
medians = df2.median(numeric_only=True)
means = df2.mean(numeric_only=True)
答案1
得分: 1
你可以尝试使用 df.mean(axis=1)
。
axis=1
将指向行而不是列。
英文:
you could try df.mean(axis=1)
.
axis=1
would point to rows instead of columns
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论