how to import csv file to anaconds kernel? - python-3.x

I am trying to import csv file to jupyter notebook but there seems to be error, Plz help with correct command.
Command : a=pd.read_csv(r"C:\Users\Priti M\Downloads\NAME LIST 19FEB PC\NAME LIST 19FEB PC.csv")

Related

How to use/install python code/file in Juypter notebooks

I got code file as data_load_util.py from Git hub. I'm following some tutorial where this import is being used. Using Python 3.x and Juypter Notebooks with connection to SAP Hana 2.0 Express Edition.
File location - https://github.com/SAP-samples/hana-ml-samples/blob/master/Python-API/pal/notebooks/data_load_utils.py
Command I'm using for tutorial:
from hana_ml import dataframe
from data_load_utils import DataSets, Settings
Error I'm getting:
ModuleNotFoundError: No module named 'data_load_utils'
Since I found this utility data_load_util.py as code file but not sure how I use this or attach this to python or juypter notebooks so that I can use code and this error will be gone.
Help will be appreciated.
Link to error screen shot
You need to tell Jupyter where to look for modules via sys.path.
From this doc, you can add your module’s sub-directory to Python's path like this:
import os
import sys
sys.path.insert(0, os.path.abspath('../module-subdirectory'))
Then you can simply import it:
from data_load_utils import DataSets, Settings
Note: Here module-subdirectory is the sub-directory that has got data_load_util.py.
For alternate methods, please refer this doc.

python throws 'NoduleNotFound' error for a module that I'm not importing

This is in python-3.7.6
I have some .pickle files that store some data I scraped off a website, each file has one snapshot of the data. Now I'm loading those snapshot files and ganging together data to form a timeseries.
I hit one file that is fine in all respects, as far as I can see, but python throws a
*** ModuleNotFoundError: No module named 'bs4'
which I'm not importing or using.
ONe time the file was zero-length. I deleted it and the script ran fine. But this file in question is fine, I can load it in ipython without any problem.
The code is...
import os, sys, re
import optparse as op
import glob
import pickle
import datetime
# and later
for f in files:
data=pickle.load(open(f,'rb') # which throws the error

How to convert a CSV file to Parquet csv2parquet in python without using Spark and Pandas

I am new to python, My current requirement is, I need to convert a CSV file to a parquet format using the csv2parquet package.
I referred to https://pypi.org/project/csv2parquet/ but did not get much clarification. Can anyone help me?
Thanks in advance.
After resolving some issues I used this code to convert a simple CSV file to parquet format, It works for me.
install the csv2parquet python package in your system.
pip install csv2parquet
Sample CSV file data
employeees_detail.csv
Python Code:
import csv2parquet
from subprocess import run
command = 'csv2parquet "C:\\Users\\Dhandapani Sudhakar\\Desktop\\employees_detail.csv"'
run(command)
After the conversion the result parquet
employees_detail.parquet
or else you can directly execute the command in the command prompt
(csvtoparquetenv) A:\POCS\Project_Envs\csvtoparquetenv>csv2parquet "C:\Users\Dhandapani Sudhakar\Desktop\employees_detail.csv"

Trying to import a .csv file in pandas using python. Getting Unicode Decode error

I am trying to import a .csv file into pandas but I am getting a Unicode error. I am running a windows pc.
I am using the following command:
medals =pd.read_csv('C:\\Users\\Username\\Downloads\\data\\olympicmedals.csv')
What am I missing here?
This is just to import a .csv file into my notebook
I am using the following command:
medals =pd.read_csv('C:\\Users\\Username\\Downloads\\data\\olympicmedals.csv')
The file should be imported into my Jupyter notebook
Try this
medals =pd.read_csv(r"C:\\Users\\Username\\Downloads\\data\\olympicmedals.csv")

Relative path not working in Pandas python in Jupyter notebook

my folder structure is :
datasets/file.csv
source/code.ipynb
from within i want to access the file named file.csv.
import pandas as pd
data = pd.read_csv("../datasets/file.csv")
This is giving me the error : ParserError: Error tokenizing data. C error: Expected 1 fields in line 68, saw 2
How to access file using relative path in pandas python?
I am using Python3.6 with Anaconda in Windows 8.1 with Jupyter notebook.
The ParseError indicates that your error is in parsing the file, not locating and opening it. To verify this, try:
test_file = open('../datasets/file.csv')
for line in test_file:
print(line.strip())
This should print out the lines in file.csv.

Resources