Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 相关性';s转换为新的CSV文件_Python_Pandas_Csv_Correlation - Fatal编程技术网

Python 相关性';s转换为新的CSV文件

Python 相关性';s转换为新的CSV文件,python,pandas,csv,correlation,Python,Pandas,Csv,Correlation,我有100个CSV文件: Merge_Prediction_Groundtruth_Speed1.0_Buffer100.csv Merge_Prediction_Groundtruth_Speed1.0_Buffer200.csv Merge_Prediction_Groundtruth_Speed1.0_Buffer300.csv Merge_Prediction_Groundtruth_Speed2.0_Buffer100.csv Merge_Prediction_Groundtruth_

我有100个CSV文件:

Merge_Prediction_Groundtruth_Speed1.0_Buffer100.csv
Merge_Prediction_Groundtruth_Speed1.0_Buffer200.csv
Merge_Prediction_Groundtruth_Speed1.0_Buffer300.csv
Merge_Prediction_Groundtruth_Speed2.0_Buffer100.csv
Merge_Prediction_Groundtruth_Speed2.0_Buffer200.csv
Merge_Prediction_Groundtruth_Speed2.0_Buffer300.csv
...............
所有CSV的结构数据如下所示:

BS      Prediction  Ground truth
BS1-BS1  0          0
BS1-BS2  0          2
BS1-BS3  2         35
BS1-BS4  0          0
BS1-BS5  0          0
BS1-BS6  0          2
BS1-BS7  0          0
BS1-BS8  0          2
BS1-BS9  0          0
BS2-BS1  0          1
...............
Files               Correlation
Speed1.0_Buffer100  0.65
Speed1.0_Buffer200  0.51
Speed1.0_Buffer300  0.73
Speed2.0_Buffer100  0.36
Speed2.0_Buffer200  0.59
Speed2.0_Buffer300  0.44
...............
我想分析预测栏和地面真相栏之间的相关性。 我使用了以下代码:

df['Prediction'].corr(df['Ground truth'])
如果我一个接一个地分析,那就要花很长时间。 是否可以根据文件的最后一个标题一次性分析相关性并同时构建到一个CSV文件中。? 我的预期结果如下所示:

BS      Prediction  Ground truth
BS1-BS1  0          0
BS1-BS2  0          2
BS1-BS3  2         35
BS1-BS4  0          0
BS1-BS5  0          0
BS1-BS6  0          2
BS1-BS7  0          0
BS1-BS8  0          2
BS1-BS9  0          0
BS2-BS1  0          1
...............
Files               Correlation
Speed1.0_Buffer100  0.65
Speed1.0_Buffer200  0.51
Speed1.0_Buffer300  0.73
Speed2.0_Buffer100  0.36
Speed2.0_Buffer200  0.59
Speed2.0_Buffer300  0.44
...............

提前感谢您。

您可以在文件夹中读取csv文件

l=['Merge_Prediction_Groundtruth_Speed1.0_Buffer100.csv',
'Merge_Prediction_Groundtruth_Speed1.0_Buffer200.csv'
...]
比如:

然后使用
concat
groupby

pd.concat(d).groupby(level=0).apply(lambda x : x['Prediction'].corr(x['Groundtruth']))

您可以在文件夹中读取csv文件

l=['Merge_Prediction_Groundtruth_Speed1.0_Buffer100.csv',
'Merge_Prediction_Groundtruth_Speed1.0_Buffer200.csv'
...]
比如:

然后使用
concat
groupby

pd.concat(d).groupby(level=0).apply(lambda x : x['Prediction'].corr(x['Groundtruth']))

非常感谢。太棒了,谢谢你。这太神奇了。