'How to display an error message when pd.read.csv fails
I use pd.read_csv to fetch GCS data.
However, when the file size is too large or something, the python task force quit
automatically at the line using pd.read_csv without displaying the error message.
I would like to display an error message to improve the script and catch the error.
How can I do that?
appended_data = []
print('loop start')
for blob in self.client.list_blobs(self.bucket, prefix=prefix):
if re.match(regexp_file_path, blob.name):
print('fetch')
df = pd.read_csv('gs://{}/{}'.format(self.bucket, blob.name), names=columns, sep='\t')
print('append')
appended_data.append(df)
print('loop end')
and, the result is below
loop start
fetch
append
fetch
append
fetch
append
fetch
append
fetch
append
fetch
I expected the script prints "append" and "loop end", but the script force quits with the last message "fetch".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|