I have recently taken up working on Python 3.6 implemented in RStudio using Miniconda and the library reticulate.
I have installed all the packages that I need using
reticulate::py_install('name of the packages')
when I try to import some .nc data as follow:
import numpy as np
import pandas as pd
import cartopy as cp
from cartopy import crs as ccrs, feature as cfeature
import matplotlib.pyplot as plt
import xarray as xr
import openpyxl
import netCDF4
#%%
adt = xr.open_dataset("G:/Research/ADT.nc")
I get this error:
NameError: name 'netCDF4' is not defined
I have looked at possible solutions, like:
netCDF4 import not being found by Python
but I have installed the package netCDF4 and xarray as the other ones, which do not give any issue (so far)
I had this error in Jupiter Notebook, but then I restarted the Kernel and ran again, and it was fine. I installed netcdf4 using conda.
Related
I'm trying to upload an audio file to Jupyter Notebook(I work with librosa), I wrote the following code:
import librosa
import librosa.display
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt
import IPython.display as ipd
%matplotlib inline
import warnings
path = 'gruesome.mp3'
audio, sr = librosa.load(path, sr=44100)
I get the following error(tell me what the problem may be, I've already spent a lot of time, I can't solve the problem, how to solve the problem?):
enter image description here
enter image description here
enter image description here
This is well covered in librosa readme.
In summary
libsndfile doesn't support MP3 due to patents.
audioread requires that you install ffmpeg or GStreamer.
For conda installations, they recommend
conda install -c conda-forge ffmpeg
You can also consider a different file format, e.g. FLAC or ogg
Edit: I should also mention that this has nothing to do with Jupyter, nor with uploading or downloading anything.
I'm currently trying to learn Python through coursera and I'm trying to run the code but I'm running into an error when I try to install nba_api. Below I have pasted my code
!pip install nba_api
# I get an 'invalid syntax error' here ^^
import pandas as pd
import matplotlib.pyplot as plt
x={'a':[11,21,31],'b':[12,22,32]}
print(x)
df=pd.DataFrame(x)
print(type(df))
print(df.head())
from nba_api.stats.static import teams
import matplotlib.pyplot as plt
Any ideas what I'm doing wrong/missing here?
! is a shorthand for calling out to the shell that is only in the REPL. You can't use this in Python files.
Instead you should put your code in a package and have a dependency on nba_api, when someone installs your package, nba_api package would also be installed.
I had to update my Macbook Air's iOS (Catalina), since I updated to this iOS's version, plotly stop working on my Jupyter-lab's enviroment.
I already followed the Getting Started's steps showed on plotly website:
$ pip install jupyterlab==1.2 "ipywidgets>=7.5"
When I run a random example, it shows an empty white block:
The libraries that I was importing (The ones that worked before):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import cufflinks as cf
from plotly.offline import download_plotlyjs,init_notebook_mode, plot,iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)
cf.go_offline()
%matplotlib inline
You need to have the relevant JupyterLab extensions installed, as per our Getting Started guide here: https://plot.ly/python/getting-started/
If you're having trouble, here is our troubleshooting guide: https://plot.ly/python/troubleshooting/
OBJECTIVE
Using Jupyter notebooks, import a csv file for data manipulation
APPROACH
Import necessary libraries for statistical analysis (pandas, matplotlib, sklearn, etc.)
Import data set using pandas
Manipulate data
CODE
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
import pandas as pd
from sklearn.cluster import KMeans
data = pd.read_csv("../data/walmart-stores.csv")
print(data)
ERROR
OSError: File b'../data/walmart-stores.csv' does not exist
FOLDER STRUCTURE
Anconda
env
kmean.ipynb
data
walmart-stores.csv
(other folders [for anaconda env])
(other folders)
QUESTION(S)
The error clearly states that the csv file cannot be found. I imagine it has to do with the project running in an Anaconda environment, but I thought this was the purpose of Anaconda environments in the first place. Am I wrong?
After answering the question, are there any other suggestions on how I should structure my Jupyter Notebooks when using Anaconda?
NOTES: I am new to python, anaconda, and jupyter notebooks so please disregard are naivety/stupidity. Thank you!
Fellow newbie here!
Try removing the "../" from your data location
Change
data = pd.read_csv("../data/walmart-stores.csv")
to
data = pd.read_csv("data/walmart-stores.csv")
EDIT: This is not solved in the suggested duplicate; reloading the module
after editing the file doesn't help.
I have a python file "/home/Misc/misc_def.py" collecting some functions that I'm using in several ipython notebooks. The first cell in each notebook is
import csv
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
%matplotlib inline
sns.set_style('white')
from sys import path
path.append('/home/Misc')
import misc_def
However, the strange thing is that sometimes this works (the notebook can find the functions in the file) and sometimes it doesn't. I'm using notebooks in different folders, but I think this shouldn't matter since it's all absolute paths. The errors I get are standard for not finding functions; e.g.
NameError: name 'get_overlap_data' is not defined
Is there something unstable about the way I do it above?