英文:
Got an unexpected keyword argument 'skiprows'
问题
I'm here to provide the translated content:
我在尝试在函数中使用skiprows时遇到了错误,并且在调用该函数时也遇到了错误。我试图在读取文件时使用skiprows来跳过行。
这是函数(rowstoskip是一个全局变量):
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)
)
这是我在其中使用它的函数:
def process_by_publisher(self, folder, rowstoskip=rowstoskip):
这是调用LoadCSV函数的那行:
rdf = self.LoadCSV(file_name, sep, rowstoskip)
这是我得到的错误:
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()收到了一个意外的关键字参数 'skiprows'
Is there anything else you would like to ask or clarify?
英文:
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'
答案1
得分: 0
你只需要更改你的`self.read_csv`调用中的参数名称。像这样,我只改变了一个单词:
```python
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)
<details>
<summary>英文:</summary>
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)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论