I have a text file name mr.txt in the hadoop file sytem under /project1 directory. I need to write the python code to read the first line of the text file without downloading mr.txt file into local. But I have trouble to open the mr.txt file from hdfs. I had tried:
open('hdfs:///project1/mr.txt','r')
Get PySpark installed.
text = sc.textFile('hdfs:///project1/mr.txt')
first_line = text.first()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With