“Got an unexpected keyword argument ‘skiprows'”

huangapple go评论52阅读模式
英文:

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>



huangapple
  • 本文由 发表于 2023年3月31日 03:06:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定