Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.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 为什么数据帧中的浮点值串联会产生NaN输出?_Python_Pandas_Floating Point_Concatenation - Fatal编程技术网

Python 为什么数据帧中的浮点值串联会产生NaN输出?

Python 为什么数据帧中的浮点值串联会产生NaN输出?,python,pandas,floating-point,concatenation,Python,Pandas,Floating Point,Concatenation,我有一堆带浮点值的数据帧。我想用熊猫来连接它们 df1 = hapX_Sp_Sum contig pos F1_2ms04h_PI 0 2 16229767 726 3.5 1 2 16229783 726 3.5 2 2 16229880 726

我有一堆带浮点值的数据帧。我想用熊猫来连接它们

df1 = 

                                 hapX_Sp_Sum
  contig pos      F1_2ms04h_PI             
0  2      16229767 726                   3.5
1  2      16229783 726                   3.5
2  2      16229880 726                   2.0
3  2      16229891 726                   2.0
4  2      16229982 726                   0.0
5  2      16229992 726                   0.0

df2 =

                                     hapX_My_Sum
  contig pos      F1_2ms04h_PI             
0  2      16229767 726                   0.0
1  2      16229783 726                   0.0
2  2      16229880 726                   0.0
3  2      16229891 726                   0.0
4  2      16229982 726                   0.0
5  2      16229992 726                   0.0
我将它们连接为:

frames = [df1, df2]
merged_df = pd.concat(frames, axis = 1)
我得到的输出:

                                     hapX_My_Sum  hapX_Sp_Sum
  contig pos      F1_2ms04h_PI                          
0  2      16229767 726                   0.0          NaN
1  2      16229783 726                   0.0          NaN
2  2      16229880 726                   0.0          NaN
3  2      16229891 726                   0.0          NaN
4  2      16229982 726                   0.0          NaN
5  2      16229992 726                   0.0          NaN
每列中的值都是一个浮点值,但是为什么我会遇到这个问题呢?我使用浮点值的
pd.sum()
生成了这些数据帧,这将导致列中的每个值都是浮点值。这很奇怪,知道吗


谢谢,

这在我看来很正常,因为您正在沿行连接。所以是的,
hapX\u Sp\u Sum
在第一个数据帧中当然是空的。如果打印更多行,您将发现非空值(但这次其他列为NaN)

我怀疑你真正想做的是


merged\u df=pd.concat(帧,轴=0)

我想我是在做轴=0,使用轴=1现在可以工作了。谢谢