0

I have a dataframe (df below) and i want to convert it to an numpy array. the variable mjd takes 1065 unique values and i was trying to get an array for each object_id all the flux corresponding to the different values of Mjd. thanks in advance for the help !

df.head()

Object_id    Mjd     flux         passband   
  615        59750   -544.81         0
  615        59750   -574.80         1
  615        59750    54             2
  615        59750    -44.810303     3
  615        59750    644.810303     4

Output : object_id X flux(mjd)

   array[(615,passband = 1, flux(mjd1), flux(mjd2)..flux(mjd1065)),
    (615,passband = 2, flux(mjd1), flux(mjd2)..flux(mjd1065))
    (615,passband = 3, NaN, flux(mjd2)..NaN)..

    (4512,passband = 4, flux(mjd1), flux(mjd2)..flux(mjd1065))]

if no flux for the corresponding Mjd, NaN is inserted.

7
  • Here are two possible links stackoverflow.com/questions/13187778/… stackoverflow.com/questions/49180018/… Commented Mar 4, 2019 at 15:23
  • thanks, already seen it, but not what i am looking for. df.to_records , df.values convert to a numpy but not to the structure i need. Commented Mar 4, 2019 at 15:32
  • What type of structure do you need?Do you want all Object_id fields that match be grouped together in a numpy array. Commented Mar 4, 2019 at 15:39
  • Yes you summarized all i want in one sentence ! Commented Mar 4, 2019 at 15:41
  • I was about to write some code up for you but I found this and perhaps if you looked through this is may help.stackoverflow.com/questions/52621497/… ... If this doesn't help let me know Commented Mar 4, 2019 at 15:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.