将List转换为pandas DataFrame

时间:2017-07-25 14:40:46

标签: list pandas dataframe

我需要构建一个具有非常特定结构的DataFrame。收益率曲线值作为数据,单个日期作为索引,成熟天数作为列名称。

CXX tools/extract_features.cpp
CXX tools/compute_image_mean.cpp
CXX tools/train_net.cpp
CXX tools/device_query.cpp
CXX tools/upgrade_solver_proto_text.cpp
CXX tools/finetune_net.cpp
CXX tools/upgrade_net_proto_text.cpp
CXX tools/upgrade_net_proto_binary.cpp
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
CXX tools/convert_imageset.cpp
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
CXX tools/caffe.cpp
CXX tools/test_net.cpp
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX examples/mnist/convert_mnist_data.cpp
CXX examples/cpp_classification/classification.cpp
CXX examples/cifar10/convert_cifar_data.cpp
CXX .build_release/src/caffe/proto/caffe.pb.cc
AR -o .build_release/lib/lenter code hereibcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: cannot find -l -lopencv_core
collect2: error: ld returned 1 exit status
Makefile:573: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1

然后我尝试创建DataFrame

In[1]: yield_data  # list of size 38, with yield values
Out[1]: 
[0.096651956137087325,
 0.0927199778042056,
 0.090000225505577847,
 0.088300016028163508,...


In[2]: maturity_data  # list of size 38, with days until maturity
Out[2]:
[6,
 29,
 49,
 70,...

In[3]: today
Out[3]: 
Timestamp('2017-07-24 00:00:00')

但它返回错误

pd.DataFrame(data=yield_data, index=[today], columns=maturity_data)

我尝试使用这些列表的转置,但它不允许转置它们。

如何创建此DataFrame?

1 个答案:

答案 0 :(得分:0)

IIUC,我认为你想要一个单行的数据帧,你需要将你的数据输入列表重塑为一个列表列表。

yield_data = [0.09,0.092, 0.091]
maturity_data = [6,10,15]
today = pd.to_datetime('2017-07-25')

pd.DataFrame(data=[yield_data],index=[today],columns=maturity_data)

输出:

              6      10     15
2017-07-25  0.09  0.092  0.091