失败代码:
import pandas as pd import numpy as np dic2 = {"a": pd.Series([1, 2, 3, 4]), "b": pd.Series([4, 5, 6, 7])} data2 = pd.DataFrame(dic2,index=["一", "二", "三", "四"]) # 创建Dataframe
输出:
a b
一 NaN NaN
二 NaN NaN
三 NaN NaN
四 NaN NaN
成功代码:
import pandas as pd import numpy as np dic2 = {"a": pd.Series([1, 2, 3, 4]), "b": pd.Series([4, 5, 6, 7])} data2 = pd.DataFrame(dic2) # 创建Dataframe data2.index =["一", "二", "三", "四"] print(data2)
输出:
a b
一 1 4
二 2 5
三 3 6
四 4 7
后面修改就无问题,学生表示不懂,请大侠赐教