I'm trying to read a .gz file from Google Cloud storage via Python on Jupyter notebook.
I get error by the first code.
TypeError: can't concat str to bytes
from google.cloud import storage
import pandas as pd
from io import StringIO
client = storage.Client()
bucket = client.get_bucket("nttcomware")
blob = bucket.get_blob(f"test.csv.gz")
df = pd.read_csv(s, compression='gzip', float_precision="high")
df.head()
I get second error by the second code.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
from google.cloud import storage
import pandas as pd
from io import StringIO
client = storage.Client()
bucket = client.get_bucket("nttcomware")
blob = bucket.get_blob(f"test.csv.gz")
bt = blob.download_as_string()
s = str(bt, "utf-8")
s = StringIO(s)
df = pd.read_csv(s, compression='gzip', float_precision="high")
df.head()
Please suggest.