- 4

Machine Learning - What’s in a column?

Machine Learning - What's in a Column? 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] My code so far Import pandas as pd df = pd.read_csv("/usercode/files/one.csv") arr = df[['a', 'b']].values print(arr.shape) filename = input() column_name = input()

6th Jul 2020, 8:30 PM
Jovani Velasco
Jovani Velasco - avatar
25 Réponses
+ 26
filename = input() column_name = input() import pandas as pd import numpy as np df = pd.read_csv(filename) # read the file as a pandas dataframe arr = np.array(df[column_name]) # transform the pretended column as a numpy array print(arr) # show the value of the array better way to understand how to do it ;)
17th Jan 2021, 12:56 AM
mauurao
mauurao - avatar
+ 15
import pandas as pd import numpy as np filename = input() column_name = input() fl= pd.read_csv(filename) print (fl[column_name].values)
9th Apr 2021, 2:39 PM
NiveL
NiveL - avatar
+ 5
Hay hay what had you did this the pro challenges. You can't post them in public . Posting pro challenges! I dont think it's fair. this might help you \/ import pandas as pd import numpy as np filename = input() column_name = input() a=pd.read_csv(filename) b=a[column_name] print(np.array(b)) your code seems very unlogical because taking input after doing all operations.!
6th Jul 2020, 11:43 PM
Ayush Kumar
Ayush Kumar - avatar
+ 4
import pandas as pd filename = input() column_name = input() df = pd.read_csv(filename) print(df[column_name].values) i did mine like this and it worked perfectly. Read the file assigned by the user to the filename and print the value of the character assigned to the column name
20th Jul 2021, 2:12 PM
Babalola Elisha
Babalola Elisha - avatar
+ 3
Who can tell what's in test ceses 3 - 5 ??? I've passed 1 and 2, but hard to guess farther if you don't know what's being checked.
29th Dec 2020, 10:41 PM
Oleksiy Zavadskyy
Oleksiy Zavadskyy - avatar
+ 3
solved import pandas as pd import numpy as np filename = input() x= pd.read_csv(filename) column_name = input() d=x[column_name].values print(np.array(d))
3rd Feb 2022, 7:11 PM
Avrian Shandy
Avrian Shandy - avatar
+ 2
this will covers all cases: import pandas as pd import numpy as np filename = input() x= pd.read_csv(filename) column_name = input() d=x[column_name].values print(np.array(d))
4th Oct 2021, 7:28 PM
Haider Daij
Haider Daij - avatar
+ 1
import pandas as pd filename = input() column_name = input() df = pd.read_csv(filename) print(df[column_name].values)
28th Aug 2021, 2:13 PM
Amitai Myers
Amitai Myers - avatar
+ 1
the answer is import pandas as pd import numpy as np filename = input() column_name = input() fl= pd.read_csv(filename) print (fl[column_name].values)
28th Nov 2021, 4:21 PM
Nabila Muftia Ma'ruf Kartono
Nabila Muftia Ma'ruf Kartono - avatar
+ 1
import pandas as pd import numpy as np filename = input() column_name = input() fl= pd.read_csv(filename) print (fl[column_name].values)
15th Dec 2021, 4:36 PM
Mirmahmud Ilyosov
Mirmahmud Ilyosov - avatar
+ 1
import numpy as np n = int(input()) X = [] for i in range(n): X.append([float(x) for x in input().split()]) y = [int(x) for x in input().split()] datapoint = [float(x) for x in input().split()] from sklearn.linear_model import LogisticRegression model = LogisticRegression() model.fit(X,y) datapoint = np.array(datapoint).reshape(1,-1) print(model.predict(datapoint[[0]])[0])
9th Nov 2022, 2:34 PM
Angela Stetsko
Angela Stetsko - avatar
+ 1
filename = input() column_name = input() import pandas as pd df = pd.read_csv(filename) print(df[column_name].values)
8th Aug 2023, 4:44 AM
Darshan Barhate
0
丹ⓨㄩک廾, thank you, it works!
9th Jan 2021, 5:05 PM
Václav Dostál
Václav Dostál - 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])
11th May 2021, 4:02 AM
Salimov Furqat
Salimov Furqat - avatar
0
I'm having a problem with the same task. If I run my code on Jupiter it works perfectly. However, on the python editor on sololearn, it is not working. Here is my code: import pandas as pd df = pd.read_csv('https://sololearn.com/uploads/files/one.csv') col = df['a'].values col2 = df['b'].values print(col) print(col2) Error: urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution> Anybody, please help. Thank you.
7th Jun 2021, 7:50 AM
ngigi
0
filename = input() column_name = input() import pandas as pd import numpy as np df = pd.read_csv(filename) # read the file as a pandas dataframe arr = np.array(df[column_name]) # transform the pretended column as a numpy array print(arr) # show the value of the array
17th Dec 2021, 9:59 AM
Ismoilov Abdug'ofur
Ismoilov Abdug'ofur - avatar
0
import pandas as pd import numpy as np filename = input() column_name = input() fl= pd.read_csv(filename) print (fl[column_name].values) #This code is right😀
29th Jan 2022, 3:18 PM
Sanjai R
0
filename = input() column_name = input() import pandas as pd #use pandas to read the csv file import numpy as np# use numpy for converting the column entries into numpy array data= pd.read_csv(filename) a= data[column_name].values print(np.array(a))
16th Mar 2022, 6:39 AM
Faiza Tiwana
Faiza Tiwana - avatar
0
filename = input() column_name = input() import pandas as pd df = pd.read_csv(filename) print(df[column_name].values)
29th Apr 2022, 1:10 PM
CHIN HENG CHU
0
Machine Learning - What's in a Column? 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]
25th Jun 2022, 11:09 AM
Worku Tamire