поведение в DF
Я вижу необъяснимое при добавлении нового столбца в DF
import pandas as pd
d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']),
'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])}
df = pd.DataFrame(d)
print(df)
# Adding a new column to an existing DataFrame object with column label by passing new series
print ("Adding a new column by passing as Series:")
df['three']=pd.Series([10,20,30],index=['a','b','c'])
print(df)
print ("Adding a new column using the existing columns in DataFrame:")
print("print df['one']")
print(df['one'])
print("#print(df['two']")
print(df['two'])
print("#print df['three']")
df['three']
print("df['four']=df['one']+df['three']")
df['four']=df['one']+df['three']
#print(df)
print(df)
Фактический результат:
one two
a 1.0 1
b 2.0 2
c 3.0 3
d NaN 4
Добавление нового столбцапередавая в виде Series:
one two three
a 1.0 1 10.0
b 2.0 2 20.0
c 3.0 3 30.0
d NaN 4 NaN
Добавление нового столбца с использованием существующих столбцов в DataFrame:
print (df ['one']):
a 1.0
b 2.0
c 3.0
d NaN
Name: one, dtype: float64
print (df ['two']):
a 1
b 2
c 3
d 4
Name: two, dtype: int64
print (df ['three']):
nothing
df ['four'] = df ['one'] + df ['three']
one two three four
a 1.0 1 10.0 11.0
b 2.0 2 20.0 22.0
c 3.0 3 30.0 33.0
d NaN 4 NaN NaN
Вопрос :
Почему я не получаю данные при печати df ["three"]?