1

I have read a data like this:

import numpy as np
arr=n.loadtext("data/za.csv",delimeter=",")
display(arr)

Now the display looks like this:

array([[5.0e+01,1.8e+00,1.6e+00,1.75+e00],
       [4.8e+01,1.77e+00,1.63e+00,1.75+e00],
       [5.5e+01,1.8e+00,1.6e+00,1.75+e00],
       ...,
       [5.0e+01,1.8e+00,1.6e+00,1.75+e00],
       [4.8e+01,1.77e+00,1.63e+00,1.75+e00],
       [5.0e+01,1.8e+00,1.6e+00,1.75+e00]])

Now I would like to give this variables to this array

the first ist weight of person second is height of person third is height of mother fourth is height of father

Now I would like to now how can I create this variables that representin the columns?

2
  • Am I understanding correctly that you would like to be able to give the array columns some names? You might want to have a look at pandas.DataFrame which does essentially this. Alternatively, you could extract a single column into a new variable, e.g. weights = arr[:,0] Commented Oct 11, 2022 at 10:20
  • yes, that's what I want give array columns some names Commented Oct 11, 2022 at 10:20

2 Answers 2

1
  1. install pandas library
  2. import pandas as pd
  3. use pd.read_csv("data/za.csv", columns= ["height", "weight", "etc"]) for read the data hope you get the solution.
Sign up to request clarification or add additional context in comments.

Comments

1

As it has already been advised, you may use pandas.read_csv for the purpose as per below:

df = pd.read_csv(**{
    'filepath_or_buffer': "data/za.csv",
    'header': None,
    'names': ('weight_of_person', 'height_of_person', 'height_of_mother', 'height_of_father'),
})

Comments

Your Answer

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