“Got an unexpected keyword argument ‘skiprows'”

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

Got an unexpected keyword argument 'skiprows'

问题

I'm here to provide the translated content:

  1. 我在尝试在函数中使用skiprows时遇到了错误并且在调用该函数时也遇到了错误我试图在读取文件时使用skiprows来跳过行
  2. 这是函数rowstoskip是一个全局变量):
  3. def LoadCSV(self, file_name, sep, rowstoskip):
  4. blop = self.bucket.blob(blob_name="{}".format(file_name.name))
  5. data = blop.download_as_string()
  6. df = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
  7. return df
  8. def read_csv(self, *args, file_name, sep, rowstoskip, badlines_collect_func):
  9. return pd.read_csv(
  10. io.BytesIO(args[0]), encoding='utf-8', sep=sep, skiprows=rowstoskip, engine='python',
  11. on_bad_lines=lambda x: badlines_collect_func(x, file_name)
  12. )
  13. 这是我在其中使用它的函数
  14. def process_by_publisher(self, folder, rowstoskip=rowstoskip):
  15. 这是调用LoadCSV函数的那行
  16. rdf = self.LoadCSV(file_name, sep, rowstoskip)
  17. 这是我得到的错误
  18. d
  19. f = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
  20. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  21. 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):

  1. def LoadCSV(self, file_name, sep, rowstoskip):
  2. blop = self.bucket.blob(blob_name="{}".format(file_name.name))
  3. data = blop.download_as_string()
  4. df = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
  5. return df
  6. def read_csv(self, *args, file_name, sep, rowstoskip, badlines_collect_func):
  7. return pd.read_csv(
  8. io.BytesIO(args[0]), encoding='utf-8', sep=sep, skiprows=rowstoskip, engine='python',
  9. on_bad_lines=lambda x: badlines_collect_func(x, file_name)

This is the function that im using it in:

  1. def process_by_publisher(self, folder, rowstoskip=rowstoskip):

This is the line that is calling the LoadCSV function:

  1. rdf = self.LoadCSV(file_name, sep, rowstoskip)

This is the error I get:
d

  1. f = self.read_csv(data, file_name=file_name.name, sep=sep, skiprows=rowstoskip, badlines_collect_func=self.badlines_collect)
  2. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3. TypeError: GoogleStorage.read_csv() got an unexpected keyword argument 'skiprows'

答案1

得分: 0

  1. 你只需要更改你的`self.read_csv`调用中的参数名称像这样我只改变了一个单词
  2. ```python
  3. def LoadCSV(self, file_name, sep, rowstoskip):
  4. blop = self.bucket.blob(blob_name="{}".format(file_name.name))
  5. data = blop.download_as_string()
  6. df = self.read_csv(data, file_name=file_name.name, sep=sep, rowstoskip=rowstoskip, badlines_collect_func=self.badlines_collect)
  7. return df
  8. def read_csv(self, *args, file_name, sep, rowstoskip, badlines_collect_func):
  9. return pd.read_csv(
  10. io.BytesIO(args[0]), encoding='utf-8', sep=sep, skiprows=rowstoskip, engine='python',
  11. on_bad_lines=lambda x: badlines_collect_func(x, file_name)
  1. <details>
  2. <summary>英文:</summary>
  3. 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)

  1. </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:

确定