Got an unexpected keyword argument 'skiprows'
Question:
Im getting an error for skiprows when I try to use it in my function and when I call the function. I am trying to use skiprows to skip rows when reading a file.
This is the function (rowstoskip is a global var):
def LoadCSV(self, file_name, sep, rowstoskip):
blop = self.bucket.blob(blob_name="{}".format(file_name.name))
data = blop.download_as_string()
df = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
return df
def read_csv(self, *args, file_name, sep, rowstoskip, badlines_collect_func):
return pd.read_csv(
io.BytesIO(args[0]), encoding='utf-8', sep=sep, skiprows=rowstoskip, engine='python',
on_bad_lines=lambda x: badlines_collect_func(x, file_name)
This is the function that im using it in:
def process_by_publisher(self, folder, rowstoskip=rowstoskip):
This is the line that is calling the LoadCSV function:
rdf = self.LoadCSV(file_name, sep, rowstoskip)
This is the error I get:
d
f = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: GoogleStorage.read_csv() got an unexpected keyword argument 'skiprows'
Answers:
All you need to change is the parameter name in your self.read_csv
call. Like this, and I have only changed one word here:
def LoadCSV(self, file_name, sep, rowstoskip):
blop = self.bucket.blob(blob_name="{}".format(file_name.name))
data = blop.download_as_string()
df = self.read_csv(data, file_name=file_name.name, sep=sep, rowstoskip=rowstoskip, badlines_collect_func=self.badlines_collect)
return df
def read_csv(self, *args, file_name, sep, rowstoskip, badlines_collect_func):
return pd.read_csv(
io.BytesIO(args[0]), encoding='utf-8', sep=sep, skiprows=rowstoskip, engine='python',
on_bad_lines=lambda x: badlines_collect_func(x, file_name)
Im getting an error for skiprows when I try to use it in my function and when I call the function. I am trying to use skiprows to skip rows when reading a file.
This is the function (rowstoskip is a global var):
def LoadCSV(self, file_name, sep, rowstoskip):
blop = self.bucket.blob(blob_name="{}".format(file_name.name))
data = blop.download_as_string()
df = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
return df
def read_csv(self, *args, file_name, sep, rowstoskip, badlines_collect_func):
return pd.read_csv(
io.BytesIO(args[0]), encoding='utf-8', sep=sep, skiprows=rowstoskip, engine='python',
on_bad_lines=lambda x: badlines_collect_func(x, file_name)
This is the function that im using it in:
def process_by_publisher(self, folder, rowstoskip=rowstoskip):
This is the line that is calling the LoadCSV function:
rdf = self.LoadCSV(file_name, sep, rowstoskip)
This is the error I get:
d
f = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: GoogleStorage.read_csv() got an unexpected keyword argument 'skiprows'
All you need to change is the parameter name in your self.read_csv
call. Like this, and I have only changed one word here:
def LoadCSV(self, file_name, sep, rowstoskip):
blop = self.bucket.blob(blob_name="{}".format(file_name.name))
data = blop.download_as_string()
df = self.read_csv(data, file_name=file_name.name, sep=sep, rowstoskip=rowstoskip, badlines_collect_func=self.badlines_collect)
return df
def read_csv(self, *args, file_name, sep, rowstoskip, badlines_collect_func):
return pd.read_csv(
io.BytesIO(args[0]), encoding='utf-8', sep=sep, skiprows=rowstoskip, engine='python',
on_bad_lines=lambda x: badlines_collect_func(x, file_name)