I am unable to import csv file in python - python

I am facing an issue regarding in python , when I import the csv file in python it is showing the data in VSCode. means file is running and successfully imported but when I want to create a report of same csv file by using from pandas_profiling import ProfileReport it shows me an error code and error mentioned:
import pandas as pd
from pandas_profiling import ProfileReport
df = pd.read_csv('housing.csv')
print(df)
profile = ProfileReport(df)
profile.to_file(output_file ="housing.html")
enter image description here
I want to generate **Pandas Profiling Report **

From the error i can guess you have some environment issues. The code you have written is errorless. Run your code in colab and you should see the results.

Related

How can I import xlsx file in to Jupiter notebook using directory?

I am trying to import an XLSX file into a Jupiter notebook using the code below but I am getting the error:
ParserError: Error tokenizing data. C error: Expected 1 fields in line 5, saw 2
How can I resolve this problem?
import pandas as pd
pd.read_xlsx("C:/Users/name/Downloads/weather_data.xlsx")
import pandas as pd
data=pd.read_xlsx("C:/Users/name/Downloads/weather_data.xlsx",error_bad_lines=False)
send a snap shot of your data

Error in data.py module "cannot import name 'wb'"

Pandas has worked fine for me for years. All of a sudden, today, I am getting this error:
File "C:\Users\Excel\Anaconda3\lib\site-packages\dautil\data.py", line 3, in <module>
from pandas.io import wb
ImportError: cannot import name 'wb'
It seems like the error is coming form data.py. Here is a screen shot.
This seemed to happen all of a sudden, and the error is triggered when I run a few different processes that call this process. I uninstalled and re-installed pandas. I am still getting the same error.
The documentation says
Starting in 0.19.0, pandas no longer supports pandas.io.data or
pandas.io.wb, so you must replace your imports from pandas.io with
those from pandas_datareader:
So, as per documentation, you should be doing this:
from pandas.io import data, wb # becomes
from pandas_datareader import data, wb
Even with pandas_datareader, the same error may happen, if this your case, then you have two solutions
for Pandas >=0.23 make sure that your pandas_datareader is > = 0.7, if for some reason you don't want to upgrade pandas_datareader to 0.7, or downgrading the pandas_datareader, then alternavly, you can do:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader as web

I am trying to upload a csv file onto Python (Azure) but am running into file IO Error does not exist

My code is:
import pandas as pd
df=pd.read_csv('Project_Wind_Data.csv'), usecols = ['U100', 'V100']) with open
('Project_Wind_Data.csv',"r") as csvfile:
I am trying to access certain columns within the csv file. I recive an error message saying that the data file does not exist
My data is in the following form:
This is must a be trivial issue but help would be much appreciated.
If your csv file is in the same working directory as your .py code, you use directly
import pandas as pd
df=pd.read_csv('Project_Wind_Data.csv'), usecols = ['U100', 'V100'])
If the file is in another directory, replace 'Project_Wind_Data.csv' with the full path to the file like c:User/Documents/file.txt

File data\SPY.csv does not exist

Just started learning python and trying to read a CSV file with pandas.
import pandas as pd
df = pd.read_csv(os.path.join(os.path.dirname(__file__), "C:\\Anaconda\\SPY.csv"))
But I get the error:
File data\SPY.csv does not exist
Tried with both one and two / and \ and ' instead of "
this is the connection string: C:\Anaconda\SPY.csv
(This is a file from yahoo finance. I first tried to call to yahoo but was unable so instead I just downloaded the file and saved it as a CSV)
The error is occurring because you are trying to join your current directory which is named "data" but your file is actually in "Anaconda".
Try a simple
import pandas as pd
df = pd.read_csv("C:\\Anaconda\\SPY.csv")
If you really want to use os.path.join, this should do:
import pandas as pd
import os
path = os.path.join("C:","Anaconda","SPY.csv")
df = pd.read_csv(path)
Also, if your SPY.csv file is in the same directory as your Python file, you should replace the path with a simple SPY.csv

fail to load arff file in python

I am quite sure that my arff files are correct, for that I have downloaded different files on the web and successfully opened them in Weka.
But I want to use my data in python, then I typed:
import arff
data = arff.load('file_path','rb')
It always returns an error message: Invalid layout of the ARFF file, at line 1.
Why this happened and how should I do to make it right?
If you change your code like in below, it'll work.
import arff
data = arff.load(open('file_path'))
Using scipy we can load arff data in python
from scipy.io import arff
import pandas as pd
data = arff.loadarff('dataset.arff')
df = pd.DataFrame(data[0])
df.head()

Categories