Google Interview Question

1 Programming, I chosen python. How to get top ten data (from last column) from comma separated flat file

Interview Answers

Anonymous

Apr 29, 2020

abc.csv - CSV file name import pandas as pd df = pd.read_csv('abc.csv') df.iloc[:,-1].head(10)

2

Anonymous

Sep 4, 2017

Could I know what do you mean by "from last column" here? Thanks

1

Anonymous

Dec 12, 2018

unix: awk -F',' '{print $NF}' test.csv |sort -r -n |head Python: f = open(r"test.csv", "r") res=[] for i in f: res.append(int(i.split(',')[-1].split('\n')[0])) print(sorted(res,reverse=True)[:10])

2

Anonymous

Sep 4, 2017

Huh, I got it cat file | awk -F',' '{print $NF}' | sort | head -n 10