Re: [julia-users] Convert DataArray to DataFrame
So I tried it this morning and it works for several sheets, but not for one. When I run this: f = openxl(Data.XLSX) test = readxl(DataFrame, f, Data!A1:C1885) I get the following error: NAException(Cannot convert DataArray with NA's to desired type) while loading In[3], in expression starting on line 2 in convert at C:\.julia\v0.3\DataArrays\src\dataarray.jl:561 in readxl_internal at C:\.julia\v0.3\ExcelReaders\src\ExcelReaders.jl:214 in readxl at C:\.julia\v0.3\ExcelReaders\src\ExcelReaders.jl:204 Any suggestions? Thanks. Brandon On Tuesday, May 19, 2015 at 7:28:59 PM UTC-4, David Anthoff wrote: Have you tried df = readxl(DataFrame, Filename.xlsx, Sheet1!A1:C4) That would return a DataFrame. Note that there is no readxlsheet that reads into a DataFrame (yet). The eventual API design I had in mind is that one can pass as a first argument the return type one desires. Right now the only option is DataFrame, otherwise it defaults to a DataArray. Cheers, David *From:* julia...@googlegroups.com javascript: [mailto: julia...@googlegroups.com javascript:] *On Behalf Of *Brandon Booth *Sent:* Tuesday, May 19, 2015 7:22 PM *To:* julia...@googlegroups.com javascript: *Subject:* [julia-users] Convert DataArray to DataFrame I feel like this should be simple to do, but I can't seem to do it. I'm using ExcelReaders and it imports as a DataArray whereas I'd like to have the data as a DataFrame. I didn't see anything in the approximately 375 pages of methods for convert. Thanks. Brandon
Re: [julia-users] Convert DataArray to DataFrame
Yep, there was a blank in the first row that I hadn't noticed. Thanks again. On Wednesday, May 20, 2015 at 10:31:13 AM UTC-4, David Anthoff wrote: I think that means you are reading an area where there is an empty cell in the first row of the range. The first row is used for the column names of the DataFrame, and so it can’t have an empty cell in it. Two possible ways out: - Make sure there are no empty cells in the first row of the range you are reading. - Change the range you read to A2:C1885, and then manually provide the names for the columns. Either by passing an array of symbols as colnames, or by passing header=false (in which case you will get auto created colnames) Best, David *From:* julia...@googlegroups.com javascript: [mailto: julia...@googlegroups.com javascript:] *On Behalf Of *Brandon Booth *Sent:* Wednesday, May 20, 2015 10:12 AM *To:* julia...@googlegroups.com javascript: *Subject:* Re: [julia-users] Convert DataArray to DataFrame So I tried it this morning and it works for several sheets, but not for one. When I run this: f = openxl(Data.XLSX) test = readxl(DataFrame, f, Data!A1:C1885) I get the following error: NAException(Cannot convert DataArray with NA's to desired type) while loading In[3], in expression starting on line 2 in convert at C:\.julia\v0.3\DataArrays\src\dataarray.jl:561 in readxl_internal at C:\.julia\v0.3\ExcelReaders\src\ExcelReaders.jl:214 in readxl at C:\.julia\v0.3\ExcelReaders\src\ExcelReaders.jl:204 Any suggestions? Thanks. Brandon On Tuesday, May 19, 2015 at 7:28:59 PM UTC-4, David Anthoff wrote: Have you tried df = readxl(DataFrame, Filename.xlsx, Sheet1!A1:C4) That would return a DataFrame. Note that there is no readxlsheet that reads into a DataFrame (yet). The eventual API design I had in mind is that one can pass as a first argument the return type one desires. Right now the only option is DataFrame, otherwise it defaults to a DataArray. Cheers, David *From:* julia...@googlegroups.com [mailto:julia...@googlegroups.com] *On Behalf Of *Brandon Booth *Sent:* Tuesday, May 19, 2015 7:22 PM *To:* julia...@googlegroups.com *Subject:* [julia-users] Convert DataArray to DataFrame I feel like this should be simple to do, but I can't seem to do it. I'm using ExcelReaders and it imports as a DataArray whereas I'd like to have the data as a DataFrame. I didn't see anything in the approximately 375 pages of methods for convert. Thanks. Brandon
RE: [julia-users] Convert DataArray to DataFrame
I think that means you are reading an area where there is an empty cell in the first row of the range. The first row is used for the column names of the DataFrame, and so it can’t have an empty cell in it. Two possible ways out: - Make sure there are no empty cells in the first row of the range you are reading. - Change the range you read to A2:C1885, and then manually provide the names for the columns. Either by passing an array of symbols as colnames, or by passing header=false (in which case you will get auto created colnames) Best, David From: julia-users@googlegroups.com [mailto:julia-users@googlegroups.com] On Behalf Of Brandon Booth Sent: Wednesday, May 20, 2015 10:12 AM To: julia-users@googlegroups.com Subject: Re: [julia-users] Convert DataArray to DataFrame So I tried it this morning and it works for several sheets, but not for one. When I run this: f = openxl(Data.XLSX) test = readxl(DataFrame, f, Data!A1:C1885) I get the following error: NAException(Cannot convert DataArray with NA's to desired type) while loading In[3], in expression starting on line 2 in convert at C:\.julia\v0.3\DataArrays\src\dataarray.jl:561 in readxl_internal at C:\.julia\v0.3\ExcelReaders\src\ExcelReaders.jl:214 in readxl at C:\.julia\v0.3\ExcelReaders\src\ExcelReaders.jl:204 Any suggestions? Thanks. Brandon On Tuesday, May 19, 2015 at 7:28:59 PM UTC-4, David Anthoff wrote: Have you tried df = readxl(DataFrame, Filename.xlsx, Sheet1!A1:C4) That would return a DataFrame. Note that there is no readxlsheet that reads into a DataFrame (yet). The eventual API design I had in mind is that one can pass as a first argument the return type one desires. Right now the only option is DataFrame, otherwise it defaults to a DataArray. Cheers, David From: julia...@googlegroups.com javascript: [mailto:julia...@googlegroups.com javascript: ] On Behalf Of Brandon Booth Sent: Tuesday, May 19, 2015 7:22 PM To: julia...@googlegroups.com javascript: Subject: [julia-users] Convert DataArray to DataFrame I feel like this should be simple to do, but I can't seem to do it. I'm using ExcelReaders and it imports as a DataArray whereas I'd like to have the data as a DataFrame. I didn't see anything in the approximately 375 pages of methods for convert. Thanks. Brandon
[julia-users] Convert DataArray to DataFrame
I feel like this should be simple to do, but I can't seem to do it. I'm using ExcelReaders and it imports as a DataArray whereas I'd like to have the data as a DataFrame. I didn't see anything in the approximately 375 pages of methods for convert. Thanks. Brandon
Re: [julia-users] Convert DataArray to DataFrame
Thanks. I figured it was something simple that I overlooked. On Tuesday, May 19, 2015 at 7:28:59 PM UTC-4, David Anthoff wrote: Have you tried df = readxl(DataFrame, Filename.xlsx, Sheet1!A1:C4) That would return a DataFrame. Note that there is no readxlsheet that reads into a DataFrame (yet). The eventual API design I had in mind is that one can pass as a first argument the return type one desires. Right now the only option is DataFrame, otherwise it defaults to a DataArray. Cheers, David *From:* julia...@googlegroups.com javascript: [mailto: julia...@googlegroups.com javascript:] *On Behalf Of *Brandon Booth *Sent:* Tuesday, May 19, 2015 7:22 PM *To:* julia...@googlegroups.com javascript: *Subject:* [julia-users] Convert DataArray to DataFrame I feel like this should be simple to do, but I can't seem to do it. I'm using ExcelReaders and it imports as a DataArray whereas I'd like to have the data as a DataFrame. I didn't see anything in the approximately 375 pages of methods for convert. Thanks. Brandon
[julia-users] Convert DataArray to DataFrame
Hi guys, I see that the command has changed to convert a DataArray into a DataFrame, so that I can then writetable and keep the data from the DataArray. The following used to work, but now flattens the array so that the DataFrame has only one column, regardless of the columns in the DataArray: a=DataArray([1. 2; 3 4]) 2x2 DataArray{Float64,2}: 1.0 2.0 3.0 4.0 b = DataFrame(a) 4x1 DataFrame |---|-| | Row # | x1 | | 1 | 1.0 | | 2 | 3.0 | | 3 | 2.0 | | 4 | 4.0 | In this example, I do not want a 4x1 DataFrame, I want the DataFrame to be the same size as the DataArray. How can I do this in the current version? Thanks, Bradley
Re: [julia-users] Convert DataArray to DataFrame
This is actually broken right now. One way to do this is found in the pull request here: https://github.com/JuliaStats/DataFrames.jl/pull/632/files But we should probably follow Simon's suggestion in that thread and change the definition of convert to apply to AbstractMatrix. -- John On Oct 29, 2014, at 9:11 AM, Bradley Setzler bradley.setz...@gmail.com wrote: Hi guys, I see that the command has changed to convert a DataArray into a DataFrame, so that I can then writetable and keep the data from the DataArray. The following used to work, but now flattens the array so that the DataFrame has only one column, regardless of the columns in the DataArray: a=DataArray([1. 2; 3 4]) 2x2 DataArray{Float64,2}: 1.0 2.0 3.0 4.0 b = DataFrame(a) 4x1 DataFrame |---|-| | Row # | x1 | | 1 | 1.0 | | 2 | 3.0 | | 3 | 2.0 | | 4 | 4.0 | In this example, I do not want a 4x1 DataFrame, I want the DataFrame to be the same size as the DataArray. How can I do this in the current version? Thanks, Bradley