【发布时间】:2018-07-11 09:27:07
【问题描述】:
我正在尝试使用 Pandas 模块获取 DataFrame 中每一列的平均值。该图像显示了我正在使用的数据的示例。
只有索引“3 to end”与计算相关。
我尝试使用此处给出的示例: how to get the average of dataframe column values
但是,结果我得到:
In: concatenated_df.mean(axis=0)
Out: Series([], dtype: float64)
谁能解释一下这个情况?
提前致谢!
我连接文件的代码:
# appending the signal column of every csv file into a single matrix
import pandas as pd
import glob
import os
path =r'mypath' # use your path
all_files = glob.glob(os.path.join(path, "*.csv"))
df_from_each_file = (pd.read_csv(f,delim_whitespace=0, usecols=[1]) for f in all_files)
concatenated_df = pd.concat(df_from_each_file, axis=1)
concatenated_df
# save concatenated_df to .csv
concatenated_df.to_csv
【问题讨论】:
-
@juanpa.arrivillaga:我提供了连接文件的代码。在图像 'concatenated_df'.. 你可以看到输出。我希望从每一列中获得平均值。我可以提供更多信息吗?
-
那不是minimal reproducible example。请阅读该链接,也许还有How to Ask。不妨看看help center。
-
@juanpa.arrivillaga:我一定会仔细阅读它们。感谢您的意见!
标签: python pandas dataframe mean