简体   繁体   English

我试图运行代码,但我仍然得到相同的错误值错误无效文件或缓冲区

[英]i was trying to run the code and im still getting same error value error invalid file or buffer

import json 
import pandas as pd 
with open(r'C:\Users\hp\Downloads\vertpoal.com_vv.json')as d:
    dictData=json.load(d) 
df=pd.read_json(dictData) 

and I'm getting error:我收到错误:

ValuErorr: invalid file path or buffer object type;<class 'dict'>

Try:尝试:

df = pd.DataFrame.from_dict(dictData)

json.load transforms JSON to a python dict which is redundant, because pd.read_json expects ' a valid JSON str, path object or file-like object ' ( https://pandas.pydata.org/docs/reference/api/pandas.read_json.html ) json.load transforms JSON to a python dict which is redundant, because pd.read_json expects ' a valid JSON str, path object or file-like object ' ( https://pandas.pydata.org/docs/reference/api/pandas .read_json.html )

import pandas as pd 
with open(r'C:\Users\hp\Downloads\vertpoal.com_vv.json')as d:
    df=pd.read_json(d)
# some further actions with df object.

You should be able to access df variable outside of with scope.您应该能够with scope 之外访问df变量。

暂无
暂无

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

相关问题 我试图为我的网站运行 url 文件,但我在 powershell 中不断收到错误 - im trying to run a url file for my website, but it i keep getting an error in powershell 我试图在 Visual Studio 代码上运行 Python 但我面临找不到文件错误 - Im Trying To Run Python On Visual Studio Code But am Facing An File Not Found Error 为什么我在这个 window 中不断收到“无效语法”错误? 但是当我在 VS Code 中运行相同的代码时它可以工作 - Why do I keep getting "Invalid Syntax" error with this code in this window? But when I run the same code in VS Code It works 尝试删除错误时出现的错误“ TypeError:无效的文件:[]” - trying to depunctuate getting the error “TypeError: invalid File: []” 尝试为 python 安装 Kivy,但我收到此错误 - Trying to install Kivy for python but im getting this error 我在centos中使用以下代码在python-pandas中读取excel文件,但我收到了错误 - im reading the excel file in python-pandas using the below code in centos but im getting error 我收到“无效语法错误”,有时名称未定义此错误请帮助我初学者 - I'm getting the "invalid syntax error" and some times name is not defined this error please help im beginner in this 我一直试图在 Python 上运行这个程序,但我一直收到相同的操作数错误。 错误代码来自第 10 行 - I keep trying to run this program on Python, but I keep getting the same operand error. The error code is coming from the 10th line 我正在尝试制作一个简单的 Discord.Py 机器人,它能够播放音乐但不断出现相同的错误 - Im trying to make a simple Discord.Py bot that is able to play music but keep getting the same error 我正在尝试部署我的 ml model 来对植物图像进行分类,但是即使路径正确,我也找不到文件错误 - Im trying to deploy my ml model which classifies plant images, but im getting file not found error even though its path is correct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM