I am taking this code from "Modeling Techniques in Predictive Analytics" by Thomas Miller:
from __future__ import division, print_function
from future_builtins import ascii, filter, hex, map, oct, zip
import pandas as pd
from pandas.tools.rplot import RPlot, TrellisGrid, GeomPoint, ScaleRandomColour
And getting the error:
No module named rplot
This code worked at one time. How can I tell if rplot is in pandas or not? Is that why I am getting this error? Could it be removed?
Related
I am trying to write a program that chooses a recipie for me to cook at random so i found a csv file to get the recipies from but when i tried running some code this happened.
I'm new to pandas so sorry if this is stupid
`
import random
import pandas as pd
import numpy as np
pd.read_csv('recipes.csv')
pd.isnull()
`
https://github.com/cweber/cookbook/blob/master/recipes.csv (this is the link to the csv file)
I have several scripts in a project folder, most of which use the same handful of standard libraries and modules. Instead of having to reiterate in every single script
import pandas as pd
import numpy as np
import datetime
import re
etc
etc
is it possible for me to place all import statements in a masterImports.py file and simply import masterImports at the top of each script ?
Yes you can.
So the basic idea is to import all the libraries in one file. Then import that file.
An example:
masterImports.py
import pandas as pd
import numpy as np
import datetime
import re
etc
etc
otherFile.py
import masterImports as mi
print(mi.datetime.datetime(2021,7,20))
Or you could use wildcard imports -
from masterImports import * # OR from masterImports import important_package
print(datetime.datetime(2021,7,20))
Do not use wildcard asterix imports because there can be name clashes
Try this, and you will see that there is no error
It's possible, although not really the done thing
To use it, you'd need to do, at the top of each script:
from master_imports import *
There are several imports that are common between some files in my project. I would like to reuse this code, concentrating it in a unique file and have just one import in the other files. Is it possible?
Or is there another way not to replicate the desired import list in multiple files?
Yes its possible. You can create a Python file with imports and then import that Python file in your code.
For Eg:
ImportFile.py
import pandas as pd
import numpy as np
import os
MainCode.py:
from ImportFile import *
#Here you can use pd,np,os and complete your code
OR
from ImportFile import pd,np
#And then use pd and np
I was trying to use the pandas.tseries.holiday module within pandas, but for some reason it was not showing up. I tried the following:
import pandas as pd
pd.tseries.<TAB>
This does give me a list of options, but holiday was among them. According to the documentation of holiday, it should be as simple as what I tried above.
This was on my system's Python. I tried it in Jupyter using Anaconda, then in Terminal and even in Emacs, but it was never found. So it must be a general design choice that I am unaware of. I have looked for clues, but all information I find tells me that importing a whole module or parts of it is a subjective choice - example: readability versus name-space pollution etc.
Eventually I just tried importing it manually (the next step would have been downloading the actual holiday file from the pandas git repository.
So I did:
from pandas.tseries import holiday # no error
holiday.<TAB>
... and I am shown all the stuff I need - great!
But what is going on here??
Looking at the actual code of holidays.py does not give me any hint as to why the file/module is not imported when I simply import pandas using the statements above.
Edit
Here is some additional information, showing how holiday is not found within pandas.tseries itself, but can be imported and used explicitly:
>>> import pandas as pd
>>> pd.tseries.holiday.USFederalHolidayCalendar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'pandas.tseries' has no attribute 'holiday'
>>> from pandas.tseries import holiday
>>> holiday.USFederalHolidayCalendar()
<pandas.tseries.holiday.USFederalHolidayCalendar object at 0x7f3b18dc7fd0>
Using simply import pandas as pd does not automatically import all sub-modules of the pandas library (as pointed out by TomAugspurger in the comments above).
This is because the __init.py__ of the pandas library does not import the everything including the holiday sub-module module.
Either adapt the __init__.py file to do so, or be aware that one must explicitly import certain sub-modules of the pandas library!
I have a problem having pandas and sklearn work together. Importing any module from sklearn, makes pandas run havoc.
This is a minimal example of my problem:
#!/usr/bin/env python
import pandas as pd
import sklearn.metrics as sk
df_train = pd.DataFrame()
print df_train
Which prints:
/usr/local/lib/python2.7/site-packages/pandas/core/config.py:570: DeprecationWarning: height has been deprecated.
warnings.warn(d.msg, DeprecationWarning)
If I comment the line where I import sklearn.metrics, everything works correctly
Help? :}
Jose
You can ignore the warning message with:
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning,
module="pandas", lineno=570)
which should be safe for now. As #Jeff notes, it'll be fixed in pandas 0.13.