[问题] pandas读特定行数转矩阵

楼主: canon760d (大喝彩)   2019-08-06 18:37:05
df=pd.read_excel('Homework7.xlsx',sheet_name=[0],index_col=0)
读取进来之后
a=df[0].values
转成矩阵
[[-10. 0.01338601]
[ -9.98 0.01365458]
[ -9.96 0.0139285 ]
变成矩阵之后,可是我想要分割成两个矩阵
但是是要
a=[[-10][-9.98]......]
b=[[0.0133][0.01365458]......]
一般分割好像不能变成上面那样
请问有什么方法可以做到吗
谢谢各位大大
作者: tsaiminghan (tsaiminghan)   2019-08-06 20:42:00
我没用过pandas, 但是这个看起来自行转好像满容易的?我指写code去转,看起来不难。
作者: iphone2003 (307)   2019-08-06 21:13:00
a[:,[0]]和a[:,[1]]就可以了
楼主: canon760d (大喝彩)   2019-08-06 22:58:00
谢谢楼上大大回答 不过我是想要分成a,b两个的话有办法吗
作者: iphone2003 (307)   2019-08-07 01:41:00
b=a[:,[1]] a=a[:[0]] 这样吧a=a[:,[0]]才对 刚刚忘了加逗号
作者: ichere (ichere)   2019-08-07 03:45:00
可以试试a.index.values把第一行提取出来
作者: sherees (ShaunTheSheep)   2019-08-07 12:52:00
iphone大正解

Links booklink

Contact Us: admin [ a t ] ucptt.com