17723

What is “setindex! not defined” error in julia?

<h3>Question</h3>

When I run my code one error occurs with my code setindex! not defined for WeakRefStrings.StringArray{String,1}

CSV File here.

using CSV EVDdata =CSV.read(raw"wikipediaEVDdatesconverted.csv") EVDdata[end-9:end,:]

And the Error Code is here

rows, cols = size(EVDdata) for j =1:cols for i = 1:rows if !isdigit(string(EVDdata[i, j])[1]) EVDdata[i,j] = 0 end end end

I am working with Julia 1.4.1 on Jupter Notebook


<h3>Answer1:</h3>

setindex!(collection, item, inds...) is the function that colection[inds...] = item gets lowered to. The error comes from the fact that CSV.read makes an immutable collection.


<h3>Answer2:</h3>

As Oscar says in his answer, setindex! tries to mutate its arguments, i.e. change the contents of your column in place. When you do CSV.read(), by default immutable columns of type CSV.Column are returned. This is done for performance reason, as it means columns don't have to be copied after parsing.

To get around this, you can do two things:

<ol><li>Pass the keyword argument CSV.read(raw"wikipediaEVDdatesconverted.csv", copycols = true) - this will copy the columns and therefore make them mutable; or</li> <li>Achieve the same by using DataFrame((raw"wikipediaEVDdatesconverted.csv"))</li> </ol>

The second way is the preferred way as CSV.read will be deprecated in the CSV.jl package.

You can see that it's current implementation is basically doing the same thing I listed in (2) above in the source here. Removing this method will allow CSV.jl not to depend on DataFrames.jl anymore.


<h3>Answer3:</h3>

It could also be done this way

col1dt = Vector{Dates.DateTime}(undef, length(col1))

for v = 1:length(col1) col1dt[v] = Dates.DateTime(col1[v], "d-u-y") end

来源:https://stackoverflow.com/questions/61995125/what-is-setindex-not-defined-error-in-julia

Recommend

  • How to fix “FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript he
  • custom navigation for different user using core UI Angular template but I am getting some weird erro
  • I need to use multiple LDAP provider. How can I check LDAP server availability?
  • What is “setindex! not defined” error in julia?
  • Navicat key
  • React | How to Pass FormikProps one Component Up
  • How to extend service in Docker Compose V3?
  • C# What is the best way to copy a BindingList?
  • Naming a variable with another variable in C
  • Ajax and returning image created by PHP GD
  • Can a C# program read a text file into memory and then pass that object to a method that requires a
  • Position a that stays at the bottom
  • Screenshot Black in Android
  • How to find references (or usages) in Atom editor?
  • When I change a .NET Button's BackColor back to its original value, it doesn't look the sa
  • Converting SVG with Embedded CSS to PDF in Python
  • Start a JobIntentService Implicitly
  • How to insert and update existing array data with one single query in Codeigniter ?
  • Getting this “org.xhtmlrenderer.render.BlockBox cannot be cast to org.xhtmlrenderer.newtable.TableBo
  • Run perl file from PHP script but not wait for output on Windows Server
  • PhoneGap FileReader/readAsDataURL Not Triggering Callbacks
  • Eloquent Javascript: Can't understand how the number value is determined in the sum function
  • how to ignore files when finishing private ClearCase branch?
  • Encounter error “IB API required” when IB API is installed
  • Allowing audio files in Spring MVC 3.0?
  • How to define something in JavaScript [closed]
  • Problems to understand DXGI DirectX 11 Desktop Duplication to get a Buffer or Array
  • Neo4j…how to get a visual representation of my data?
  • Amazon Elastick BeanStalk error: Failed to create the AWS Elastic Beanstalk application version
  • Can a PHP script be scheduled to run at a specific time or after a specific amount of time has expir
  • Bitrate JWplayer
  • Accessing Arguments, Workflow Variables from custom activities
  • JavaScript RegExp Replace