I need to read first 2 rows of csv file and store that in array to determine file_type,reportingdate and other metadata. My file is in Google cloud Storage.How can I read first 2 rows and store that in array in python script . I am trying with below code :
storage_client = storage.Client()
from google.cloud import storage
bucket = storage_client.get_bucket('glrs_test_deepshikha')
blob = storage.Blob('67_glrs_intercompany_override_2rows_duplicates.csv', bucket)
content = blob.download_as_string()
for row in content:
print (row)
It is printing the csv data but every character is being printed as string. I need row data in array. Any help will be much appreciated.
Due to the function name, I am assuming that the content variable is one very long string. If that is the case, then there ought to be newline characters in the string. You can simply split the string using newline as a delimiter and grab the first two values. Something like this: