import numpy as np
import pandas as pd
val=[18.15, 18.16, 17.89, 17.7, 636304.19, -0.58, -3.14, 18.452, 18.223, 17.899, 636911.59 ,626663.57, 550736.96]
ind=['开盘价','最高价','收盘价','最低价','成交量','价格变动','涨跌幅','5日均价','10日均价','20日均价','5日均量','10日均量','20日均量']
s=pd.Series(data=val,index=ind)
print('输出均价均量:')
day5=pd.DataFrame(data=s[[7,10]].values,index=None,columns=s[[7,10]].index)
print(day5)
以上部分的输出有问题
ValueError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_203228\3916060400.py in <module>
5 s=pd.Series(data=val,index=ind)
6 print('输出均价均量:')
----> 7 day5=pd.DataFrame(data=s[[7,10]].values,index=None,columns=s[[7,10]].index)
8 print(day5)
D:\Anoconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
692 )
693 else:
--> 694 mgr = ndarray_to_mgr(
695 data,
696 index,
D:\Anoconda3\lib\site-packages\pandas\core\internals\construction.py in ndarray_to_mgr(values, index, columns, dtype, copy, typ)
349 )
350
--> 351 _check_values_indices_shape_match(values, index, columns)
352
353 if typ == "array":
D:\Anoconda3\lib\site-packages\pandas\core\internals\construction.py in _check_values_indices_shape_match(values, index, columns)
420 passed = values.shape
421 implied = (len(index), len(columns))
--> 422 raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")
423
424
ValueError: Shape of passed values is (2, 1), indices imply (2, 2)
想知道如何能有如下输出
输出均价均量:
5日均价 5日均量
18.452 636911.59