Machine Learning - What’s in a column? | Sololearn: Learn to code for FREE!

-3

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()

7/6/2020 8:30:01 PM

Jovani Velasco

19 Answers

New Answer

+18

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 ;)

+8

import pandas as pd import numpy as np filename = input() column_name = input() fl= pd.read_csv(filename) print (fl[column_name].values)

+4

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.!

+4

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.

+2

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

+2

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))

+1

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))

+1

import pandas as pd import numpy as np filename = input() column_name = input() fl= pd.read_csv(filename) print (fl[column_name].values)

0

丹ⓨㄩک廾, thank you, it works!

0

import pandas as pd df = pd.read_csv('https://sololearn.com/uploads/files/one.csv') arr = df[['a', 'b']].values print(arr[:,0])

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.

0

import pandas as pd filename = input() column_name = input() df = pd.read_csv(filename) print(df[column_name].values)

0

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)

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

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😀

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))

0

filename = input() column_name = input() import pandas as pd df = pd.read_csv(filename) print(df[column_name].values)

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]

0

Question is when we input a column name then values will be come from column name #include pandas import pandas as pd #import numpy as np--- not need here we change pandas to numpy use by values keyword file_name = input() #declartion for filename df= pd.read_csv(file_name) #mention above file name here!!!!read the file as a pandas dataframe column_name = input() #column name decalration output=df[column_name].values #mention here above coumn name print(output)