由于s和t的索引相同,为什么t返回NaN作为第一个值?

问题描述 投票:0回答:1

系列t的第一个值是NaN,而不是s。为什么即使系列具有相同的索引也是如此。

import numpy as np
import pandas as pd
s = pd.Series([1,2,3,4,5,6],index= [1,2,3,4,5,6])
t = pd.Series([2,4,6,8,10,12],index= [1,2,3,4,5,6])
df = pd.DataFrame(np.c_[s,t],columns = ["MUL1","MUL2"])
df["MUL2"] =t

df


Output:

  MUL1     MUL2
0  1        NaN
1  2        2.0
2  3        4.0
3  4        6.0
4  5        8.0
5  6        10.0
python pandas numpy dataframe series
1个回答
0
投票

问题是np.c_返回没有索引值的二维数组:

© www.soinside.com 2019 - 2024. All rights reserved.