[英]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)
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
orbytes
object representing a path, or an object implementing theos.PathLike
protocol类似路径的 object 是
str
或bytes
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.也不清楚这条线的目的是什么,我建议删除或重写它。
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.