简体   繁体   English

join() 参数必须是 str 或 bytes,而不是 'DataFrame' 错误

[英]join() argument must be str or bytes, not 'DataFrame' error

alright, I apologize for the dumb question but I would really appreciate some help on this one.好吧,我为这个愚蠢的问题道歉,但我真的很感谢在这个问题上提供一些帮助。 I am trying to analyze a cash game I played in, but seem to be having some trouble.我正在尝试分析我玩过的现金游戏,但似乎遇到了一些麻烦。 I can get the file to open and read but when I reference it to search in it I come up with a lot of issues.我可以打开和读取文件,但是当我引用它进行搜索时,我遇到了很多问题。 The title is the current issue I am having which was implemented because it seemed that it might serve as a solution to another problem I was having.标题是我当前遇到的问题,因为它似乎可以解决我遇到的另一个问题。 Thanks for any help in advance!提前感谢您的帮助!

(the natural formatting of each line of code on here didn't translate well so the site is making me link to the paste of the picture instead. The lines of code are still below however.) (这里每一行代码的自然格式翻译得不好,所以网站让我链接到图片的粘贴。但是代码行仍然在下面。)

在此处输入图像描述

#find the nunmeber of hands played in this cash game
import pandas as pd
import os
import pprint

dataDirectory = r'C:\ACR\ACR CASHGAME 10 25.txt'
handHistory = pd.read_csv(dataDirectory, sep='\n')

handHistory = os.path.join(r'C:\ACR\ACR CASHGAME 10 25.txt', handHistory)
#when I remove the line above from the code, it says dataDirectory file does not exist even though it reads it in previous lines fine.


numberofHands = pd.read_csv('dataDirectory',dtype=object)
for key in handhistory:
    if handHistory[key] == 'Hand':
        numberofHands.count(key)

os.path.join Error os.path.join 错误

You are seeing this error because in this line您看到此错误是因为在这一行

handHistory = pd.read_csv(dataDirectory, sep='\n')

You define handHistory to be a pandas.DataFrame ( pandas.read_csv() returns pandas.DataFrame ), whereas in this line: You define handHistory to be a pandas.DataFrame ( pandas.read_csv() returns pandas.DataFrame ), whereas in this line:

handHistory = os.path.join(r'C:\ACR\ACR CASHGAME 10 25.txt', handHistory)

you are calling os.path.join() which, as per documentation:您正在调用os.path.join() ,根据文档:

Join[s] one or more path components intelligently.智能地加入一个或多个路径组件。

It expects the path components to be path-like objects where:它期望路径组件是 类似路径的对象,其中:

A path-like object is either a str or bytes object representing a path, or an object implementing the os.PathLike protocol类似路径的 object 是strbytes object 表示路径,或者是实现os.PathLike协议的 object

while you are passing in a DataFrame .当您传入DataFrame

This cannot work because os.path.join() doesn't know what to do with a DataFrame .这不起作用,因为os.path.join()不知道如何处理DataFrame

It is also not clear what this line is meant to achieve and I would suggest removing or rewriting it.也不清楚这条线的目的是什么,我建议删除或重写它。

dataDirectory Error数据目录错误

The error that you are getting when removing the line删除行时遇到的错误

handHistory = pd.read_csv(dataDirectory, sep='\n')

happens because in the next line:发生是因为在下一行:

numberofHands = pd.read_csv('dataDirectory',dtype=object)

you are passing in 'dataDirectory' as a string (in single quotes ' ) into pandas.read_csv() which expects a path or file object.您将'dataDirectory'作为字符串(在单引号'中)传递到pandas.read_csv()中,它需要一个路径或文件 object。

Try removing the single quotes, ie:尝试删除单引号,即:

numberofHands = pd.read_csv(dataDirectory, dtype=object)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:join() 参数必须是 str 或 bytes,而不是“dict” - TypeError: join() argument must be str or bytes, not 'dict' TypeError: join() 参数必须是 str 或 bytes,而不是 'list' - TypeError: join() argument must be str or bytes, not 'list' 类型错误:join() 参数必须是 str 或字节,而不是“PosixPath” - TypeError: join() argument must be str or bytes, not 'PosixPath' Python错误:参数1必须为缓冲区或字节,不能为str - Python Error: Argument 1 must be buffer or bytes not str 参数必须是str而不是字节 - Argument must be str not bytes 联系表单上的 Django 错误 - join() 参数必须是 str、bytes 或 os.PathLike object, - Django error on contact form - join() argument must be str, bytes, or os.PathLike object, os.path.join 抛出错误'参数类型必须是 str 或字节不是 TextIOWrapper' - os.path.join throws error 'type of argument must be str or bytes not TextIOWrapper' join() 参数必须是 str、bytes 或 os.PathLike object,而不是“NoneType” - join() argument must be str, bytes, or os.PathLike object, not 'NoneType' TypeError:必须是str,而不是字节Error - TypeError: must be str, not bytes Error 编码:TypeError:write()参数必须是str,而不是bytes - Encoding: TypeError: write() argument must be str, not bytes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM