在八度数据框中设置列值
set column values in octave dataframe
我有两组数据如下;
file a:
1476356687
1476356689
1476356690
file b:
"2016-10-13 12:04:47.706193",1000,516130
"2016-10-13 12:04:49.225305",2000,516130
"2016-10-13 12:04:50.439240",3000,516130
new_col=dataframe("file_a")
df=dataframe("file_b")
>> size(new_col)
ans =
3 1
>> size(df)
ans =
3 3
>> new_col(1:3,:)
ans = dataframe with 3 rows and 1 columns
_1 new_col
Nr double
1 1476356687
2 1476356689
3 1476356690
>> df(1:3,:)
ans = dataframe with 3 rows and 3 columns
Src: import_nbu_op
_1 X1 X2 X3
Nr char double double
1 2016-10-13 12:04:47.706193 1000 516130
2 2016-10-13 12:04:49.225305 2000 516130
3 2016-10-13 12:04:50.439240 3000 516130
我正在尝试将 df 的第 1 列设置为 new_col,或者构建一个 new_col 的新数据框和 df
的第 2:end 列
我已经尝试了很多东西,但无法弄清楚让它工作的魔法咒语....来自 python 之类的东西,这简直是疯了 ;)
我试过了,
>> df=dataframe(new_col,df)
error: Concatenating dataframes: use cat instead
error: called from
dataframe at line 568 column 5
>> df=cat(new_col,df)
error: Incorrect call to cat
error: called from
cat at line 197 column 7
>> df=cat(1,new_col,df)
error: Different number of columns in dataframes
error: called from
cat at line 50 column 11
>> df=cat(2,new_col,df)
df(1): out of bound 0
error: called from
display at line 66 column 7
>> df=cat(0,new_col,df)
error: Incorrect call to cat
error: called from
cat at line 197 column 7
display at line 66 column 7
>> cat(2,1,new_col,df)
error: Different number of rows in dataframes
error: called from
cat at line 109 column 11
>> cat(2,2,new_col,df)
error: Different number of rows in dataframes
error: called from
cat at line 109 column 11
>> horzcat(new_col,df)
error: df(2): out of bound 1
error: called from
display at line 66 column 7
>> df(:,1)=new_col
error: cast: TYPE must be a string
error: called from
cast at line 67 column 5
df_matassign at line 452 column 31
subsasgn at line 217 column 10
>> dataframe(df,new_col)
error: Concatenating dataframes: use cat instead
error: called from
dataframe at line 568 column 5
然后,我想到了尤里卡!差不多好了!至少我现在可以将列添加到框架中了...
>> dataframe(df,new_col.array(:,:))
ans = dataframe with 3 rows and 4 columns
Src: import_nbu_op
_1 X1 X2 X3 X
Nr char double double double
1 2016-10-13 12:04:47.706193 1000 516130 1476356687
2 2016-10-13 12:04:49.225305 2000 516130 1476356689
3 2016-10-13 12:04:50.439240 3000 516130 1476356690
非常好。所以我只需要交换 df 和 new_col 来创建我(几乎)想要的框架!仅几步之遥:)
>> dataframe(new_col.array(:,:),df)
error: Concatenating dataframes: use cat instead
error: called from
dataframe at line 568 column 5
啊!为什么?
>> cat(1,new_col,df(:,2:end))
error: Different number of columns in dataframes
error: called from
cat at line 50 column 11
>> cat(2,new_col,df(:,2:end))
error: df(2): out of bound 1
error: called from
display at line 66 column 7
>> horzcat(new_col,df(:,2:end))
error: df(2): out of bound 1
求助! - 我尝试了比这更多的各种排列组合,但都以相同的方式结束:(
我使用它的 .cell
属性 与您尝试的 .array
相反:
>> concatenated = dataframe(cat(2, new_col.cell, df.cell))
concatenated = dataframe with 3 rows and 7 columns
_1 unnamed X unnamed1 unnamed2 X1 X2 X3
Nr char double double char char double double
1 1.4764e+09 1 2016-10-13 12:04:47.706193 1000 516130
2 1.4764e+09 2 2016-10-13 12:04:49.225305 2000 516130
3 1.4764e+09 3 2016-10-13 12:04:50.439240 3000 516130
然而,这会导致第 1、3 和 4 列为伪影(大概 1 和 4 来自空 space 字符,而 3 是之前的 'ascending index' 数字)。所以我不得不删除这些以获取我的数据框:
>> concatenated(:,[1,3,4]) = []
concatenated = dataframe with 3 rows and 4 columns
_1 X X1 X2 X3
Nr double char double double
1 1.4764e+09 2016-10-13 12:04:47.706193 1000 516130
2 1.4764e+09 2016-10-13 12:04:49.225305 2000 516130
3 1.4764e+09 2016-10-13 12:04:50.439240 3000 516130
虽然我同意,这个包裹看起来确实很破。
PS。 dataframe
pkg 特定于八度。这个问题与matlab无关。 Matlab 提供 dataset
和 table
classes(我还看到了 datamatrix
class 和 dataframe
文件交换)。 =19=]
我有两组数据如下;
file a:
1476356687
1476356689
1476356690
file b:
"2016-10-13 12:04:47.706193",1000,516130
"2016-10-13 12:04:49.225305",2000,516130
"2016-10-13 12:04:50.439240",3000,516130
new_col=dataframe("file_a")
df=dataframe("file_b")
>> size(new_col)
ans =
3 1
>> size(df)
ans =
3 3
>> new_col(1:3,:)
ans = dataframe with 3 rows and 1 columns
_1 new_col
Nr double
1 1476356687
2 1476356689
3 1476356690
>> df(1:3,:)
ans = dataframe with 3 rows and 3 columns
Src: import_nbu_op
_1 X1 X2 X3
Nr char double double
1 2016-10-13 12:04:47.706193 1000 516130
2 2016-10-13 12:04:49.225305 2000 516130
3 2016-10-13 12:04:50.439240 3000 516130
我正在尝试将 df 的第 1 列设置为 new_col,或者构建一个 new_col 的新数据框和 df
的第 2:end 列我已经尝试了很多东西,但无法弄清楚让它工作的魔法咒语....来自 python 之类的东西,这简直是疯了 ;)
我试过了,
>> df=dataframe(new_col,df)
error: Concatenating dataframes: use cat instead
error: called from
dataframe at line 568 column 5
>> df=cat(new_col,df)
error: Incorrect call to cat
error: called from
cat at line 197 column 7
>> df=cat(1,new_col,df)
error: Different number of columns in dataframes
error: called from
cat at line 50 column 11
>> df=cat(2,new_col,df)
df(1): out of bound 0
error: called from
display at line 66 column 7
>> df=cat(0,new_col,df)
error: Incorrect call to cat
error: called from
cat at line 197 column 7
display at line 66 column 7
>> cat(2,1,new_col,df)
error: Different number of rows in dataframes
error: called from
cat at line 109 column 11
>> cat(2,2,new_col,df)
error: Different number of rows in dataframes
error: called from
cat at line 109 column 11
>> horzcat(new_col,df)
error: df(2): out of bound 1
error: called from
display at line 66 column 7
>> df(:,1)=new_col
error: cast: TYPE must be a string
error: called from
cast at line 67 column 5
df_matassign at line 452 column 31
subsasgn at line 217 column 10
>> dataframe(df,new_col)
error: Concatenating dataframes: use cat instead
error: called from
dataframe at line 568 column 5
然后,我想到了尤里卡!差不多好了!至少我现在可以将列添加到框架中了...
>> dataframe(df,new_col.array(:,:))
ans = dataframe with 3 rows and 4 columns
Src: import_nbu_op
_1 X1 X2 X3 X
Nr char double double double
1 2016-10-13 12:04:47.706193 1000 516130 1476356687
2 2016-10-13 12:04:49.225305 2000 516130 1476356689
3 2016-10-13 12:04:50.439240 3000 516130 1476356690
非常好。所以我只需要交换 df 和 new_col 来创建我(几乎)想要的框架!仅几步之遥:)
>> dataframe(new_col.array(:,:),df)
error: Concatenating dataframes: use cat instead
error: called from
dataframe at line 568 column 5
啊!为什么?
>> cat(1,new_col,df(:,2:end))
error: Different number of columns in dataframes
error: called from
cat at line 50 column 11
>> cat(2,new_col,df(:,2:end))
error: df(2): out of bound 1
error: called from
display at line 66 column 7
>> horzcat(new_col,df(:,2:end))
error: df(2): out of bound 1
求助! - 我尝试了比这更多的各种排列组合,但都以相同的方式结束:(
我使用它的 .cell
属性 与您尝试的 .array
相反:
>> concatenated = dataframe(cat(2, new_col.cell, df.cell))
concatenated = dataframe with 3 rows and 7 columns
_1 unnamed X unnamed1 unnamed2 X1 X2 X3
Nr char double double char char double double
1 1.4764e+09 1 2016-10-13 12:04:47.706193 1000 516130
2 1.4764e+09 2 2016-10-13 12:04:49.225305 2000 516130
3 1.4764e+09 3 2016-10-13 12:04:50.439240 3000 516130
然而,这会导致第 1、3 和 4 列为伪影(大概 1 和 4 来自空 space 字符,而 3 是之前的 'ascending index' 数字)。所以我不得不删除这些以获取我的数据框:
>> concatenated(:,[1,3,4]) = []
concatenated = dataframe with 3 rows and 4 columns
_1 X X1 X2 X3
Nr double char double double
1 1.4764e+09 2016-10-13 12:04:47.706193 1000 516130
2 1.4764e+09 2016-10-13 12:04:49.225305 2000 516130
3 1.4764e+09 2016-10-13 12:04:50.439240 3000 516130
虽然我同意,这个包裹看起来确实很破。
PS。 dataframe
pkg 特定于八度。这个问题与matlab无关。 Matlab 提供 dataset
和 table
classes(我还看到了 datamatrix
class 和 dataframe
文件交换)。 =19=]