function tab = q57081181()
% Import pandas:
pd = py.importlib.import_module('pandas');
% Create a dataframe:
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv');
% Convert to a table, going throgh dictionary and struct:
st = struct(iris.to_dict());
st2 = structfun( @(x)py.list(x.values), st, 'UniformOutput', false);
tab = struct2table( importMixedData(st2) );
function out = importMixedData(inStruct)
% Import numpy:
np = py.importlib.import_module('numpy');
% Copy fieldnames:
out = inStruct;
% Convert every field separately:
fields = fieldnames(inStruct);
for f = 1:numel(fields)
fld = fields{f};
try % this should work for numeric values:
out.(fld) = double(np.array(inStruct.(fld))).';
catch % this should work for text values:
out.(fld) = string(cell(inStruct.(fld))).';
end
end
这可能不是最好的方法,但它可以给你一些新的想法:
对于输入的情况:
我们得到:
使用python3.6在R2019a上测试。你知道吗
相关问题 更多 >
编程相关推荐