pandas模块中的输出选项

时间:2017-08-10 19:40:24

标签: python-3.x pandas

下面我提到了我的python脚本,我的input_file格式和输出。我不知道如何才能获得预期的输出。

我的剧本:

import pandas as pd

A = pd.read_csv('PB-Energy-A.txt', sep="\s+", header=None)
print (A.mean())

B = pd.read_csv('PB-Energy-B.txt', sep="\s+", header=None)   
print (B.mean())

Complex = pd.read_csv('PB-Energy-complex.txt', sep="\s+", header=None)
print (Complex.mean())

File_Look_like:

PB-能量A.TXT

-1598.86
-1640.70
-1632.16
-1701.46

PB-能量B.txt

-8.82
-8.82
-8.82
-8.82

PB-能量complex.txt

-1598.90
-1640.69
-1632.15
-1701.48

输出:

0   -1626.801148
dtype: float64
0   -8.82
dtype: float64
0   -1626.807131
dtype: float64

预期产出:

A = -1626.801148
B = -8.82
Complex = -1626.807131   

2 个答案:

答案 0 :(得分:1)

以您想要的格式获取输出。在print语句中为平均值添加标签,标签和变量用逗号分隔,如下所示:

In: print("A = ", A.mean())

Out: A = -1626.801148

答案 1 :(得分:0)

我认为你需要:

a = pd.Series([-1626.801148])
print (a)
0   -1626.801148
dtype: float64

print ('A = {}'.format(a[0]))
A = -1626.801148
a = pd.Series([-1626.801148])
b = pd.Series([-8.82])
c = pd.Series([-1626.807131])

out = '''A = {0}
B = {1}
Complex = {2}'''.format(a[0],b[0],c[0])
print (out)
A = -1626.801148
B = -8.82
Complex = -1626.807131