フィルターのクリア

Cell column to double from table

2 ビュー (過去 30 日間)
Amina Ag
Amina Ag 2021 年 5 月 23 日
コメント済み: Amina Ag 2021 年 5 月 27 日
Hello,
I have a txt file that i have uploaded using readtable. This gives me a table of 4000000x34 variables. Some of these variabled are doubles, while some are cells. I have tried to transform the cell coulmns to doubles using cell2mat and str2double, but only get NaNs or error messages.
Some of my variables look like this: The cell ones containt the '''.
How can I transform the cell columns to doubles? Will need this when running my regression.
  6 件のコメント
dpb
dpb 2021 年 5 月 25 日
編集済み: dpb 2021 年 5 月 26 日
There is no item_33 in the uploaded dataset so I dunno about that.
When your data aren't properly formatted, somtimes detectimportoptions needs some extra help:
opt=detectimportoptions('b.xlsx');
opt=setvaropts(opt,'item_2','Type','categorical','FillValue','YourFillValue','Prefixes',"'",'Suffixes',"'");
opt=setvaropts(opt,'item_50108','Type','double','TrimNonNumeric',true);
tB=readtable('b.xlsx',opt);
yields
>> tB(1:8,{'item_2','item_50108'})
ans =
8×2 table
item_2 item_50108
_____________ __________
M 63.40
M 51.62
M 0.00
M 45.31
YourFillValue 51.54
M 22.22
M 70.20
M 22.12
>>
You can deal with all of the issues either by defining the import objects fields to match known data types and formats or by cleaning up the data fields afterwards.
The problem with your categorical substitution is you undoubtedly didn't have a categorical variable on the RHS and you'll have to use the form shown in the documentation for categorical to add categories for values that aren't in the dataset that is converted if don't use the fill missing on import route as shown above.
Amina Ag
Amina Ag 2021 年 5 月 27 日
This worked perfectly!
Thank you so much for your help. It has been a real struggle and feels amazing now that it is solved. Highly appreciate your time and answer.
All the best!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by