0

Getting numpy array from dataframe

Getting a column from a numpy array. Task Given a csv file and a column name, print the elements in the given column. Input Format First line: filename of a csv file Second line: column name Output Format Numpy array Sample Input https://sololearn.com/uploads/files/one.csv a File one.csv contents: a,b 1,3 2,4 Sample Output [1 2]

15th Apr 2020, 10:28 AM
Nks
Nks - avatar
4 Answers
0
You can learn about pandas to deal with csv files and numpy for multidimensional arrays
15th Apr 2020, 8:40 PM
Abhay
Abhay - avatar
0
I know basics of pandas and numpy and I have been trying to write the code. But each time there is some error and I am not getting it. I tried many different inputs
16th Apr 2020, 10:44 AM
Nks
Nks - avatar
0
import pandas as pd df = pd.read_csv('https://sololearn.com/uploads/files/one.csv') arr = df[['a', 'b']].values print(arr[:,0]) i wrote this but not correct. tried different tweaks but still can’t get the corect answer. i try putting in Code Playground elsewhere it works but not at the End of Module Project
11th Jan 2021, 11:06 PM
Chin Eu
Chin Eu - avatar
0
filename = input() column_name = input() import pandas as pd df=pd.read_csv(filename) arr=df[column_name].values print(arr) filename and column_name are arguments that user will input and just write those args inside the function u can get the ans
15th Feb 2021, 4:01 PM
Anoy Santra