Related
Error: Traceback (most recent call last):
File "C:\Users\Santosh Kumar\AppData\Local\JetBrains\PyCharm Community Edition 2022.2.2\plugins\python-ce\helpers\packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='main', alter_sys=True)
File "C:\Users\Santosh Kumar\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\Santosh Kumar\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Santosh Kumar\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\Santosh Kumar\PycharmProjects\pythonProject2\venv\lib\site-packages\pip_main.py", line 29, in
from pip._internal.cli.main import main as _main
File "C:\Users\Santosh Kumar\PycharmProjects\pythonProject2\venv\lib\site-packages\pip_internal\cli\main.py", line 9, in
from pip._internal.cli.autocompletion import autocomplete
File "C:\Users\Santosh Kumar\PycharmProjects\pythonProject2\venv\lib\site-packages\pip_internal\cli\autocompletion.py", line 10, in
from pip._internal.cli.main_parser import create_main_parser
File "C:\Users\Santosh Kumar\PycharmProjects\pythonProject2\venv\lib\site-packages\pip_internal\cli\main_parser.py", line 8, in
from pip._internal.cli import cmdoptions
File "C:\Users\Santosh Kumar\PycharmProjects\pythonProject2\venv\lib\site-packages\pip_internal\cli\cmdoptions.py", line 29, in
from:
pip._internal.models.target_python
import TargetPython
ModuleNotFoundError: No module named 'pip._internal.models.target_python'
I'm a Python3 newcomer, and I recently get a strange behavior when printing a set of random integers.
I sometimes get a perfectly sorted set, and sometimes not!
Does somebody know the reason why?
Here is my Python3 code:
import random
n=random.randint(30,90)
print("n=",n)
ens=set()
while len(ens)!=n:
ens.add(random.randint(100,199))
print("len(ens)=",len(ens))
print("ens=",str(ens))
car=input("...?")
Here is one non-sorted resulting text:
n= 84
len(ens)= 84
ens= {128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 147, 148, 150, 151, 152, 154, 156, 157, 158, 160, 161, 162, 163, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 177, 178, 179, 181, 182, 183, 185, 186, 188, 189, 190, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 116, 117, 118, 119, 121, 123, 124, 125, 126, 127}
...?
And another sorted resulting text:
n= 86
len(ens)= 86
ens= {100, 102, 103, 104, 105, 106, 107, 108, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 143, 144, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 168, 169, 170, 171, 173, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 186, 188, 189, 191, 192, 195, 196, 197, 198, 199}
...?
I know Python sets are unordered collection of items, but then, why do some of my outputs appear to be perfectly sorted, and some are not?
Just in case it is convincing, I either use Geany IDE, Thonny IDE, or directly Python 3.8 (under Win7 32bit).
Sets are unordered, so when you print your set, python doesn't know what order to print the items, so it prints them in sorted order.
>>> s = {5, 2, 3, 4, 6}
>>> print(s)
{2, 3, 4, 5, 6}
If you want to have the items ordered, use a list.
>>> l = [5, 2, 3, 4, 6]
>>> print(l)
[5, 2, 3, 4, 6]
Any ideas on how to export the yearly seasonal trend using fbprophet library?
The plot_components() function plots the trend, yearly, and weekly.
I want to obtain the values for yearly only.
Example data:
import pandas as pd
from fbprophet import Prophet
import matplotlib.pyplot as plt
df = pd.DataFrame.from_dict({'ds': ['1949-01', '1949-02', '1949-03', '1949-04', '1949-05', '1949-06',
'1949-07', '1949-08', '1949-09', '1949-10', '1949-11', '1949-12',
'1950-01', '1950-02', '1950-03', '1950-04', '1950-05', '1950-06',
'1950-07', '1950-08', '1950-09', '1950-10', '1950-11', '1950-12',
'1951-01', '1951-02', '1951-03', '1951-04', '1951-05', '1951-06',
'1951-07', '1951-08', '1951-09', '1951-10', '1951-11', '1951-12',
'1952-01', '1952-02', '1952-03', '1952-04', '1952-05', '1952-06',
'1952-07', '1952-08', '1952-09', '1952-10', '1952-11', '1952-12',
'1953-01', '1953-02', '1953-03', '1953-04', '1953-05', '1953-06',
'1953-07', '1953-08', '1953-09', '1953-10', '1953-11',
'1953-12',
'1954-01', '1954-02', '1954-03', '1954-04', '1954-05', '1954-06',
'1954-07', '1954-08', '1954-09', '1954-10', '1954-11', '1954-12',
'1955-01', '1955-02', '1955-03', '1955-04', '1955-05', '1955-06',
'1955-07', '1955-08', '1955-09', '1955-10', '1955-11', '1955-12',
'1956-01', '1956-02', '1956-03', '1956-04', '1956-05', '1956-06',
'1956-07', '1956-08', '1956-09', '1956-10', '1956-11', '1956-12',
'1957-01', '1957-02', '1957-03', '1957-04', '1957-05', '1957-06',
'1957-07', '1957-08', '1957-09', '1957-10', '1957-11', '1957-12',
'1958-01', '1958-02', '1958-03', '1958-04', '1958-05', '1958-06',
'1958-07', '1958-08', '1958-09', '1958-10', '1958-11', '1958-12',
'1959-01', '1959-02', '1959-03', '1959-04', '1959-05', '1959-06',
'1959-07', '1959-08', '1959-09', '1959-10', '1959-11', '1959-12',
'1960-01', '1960-02', '1960-03', '1960-04', '1960-05', '1960-06',
'1960-07', '1960-08', '1960-09', '1960-10', '1960-11', '1960-12'],
'y': [112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 104, 118, 115, 126,
141, 135, 125, 149, 170, 170, 158, 133, 114, 140, 145, 150, 178, 163,
172, 178, 199, 199, 184, 162, 146, 166, 171, 180, 193, 181, 183, 218,
230, 242, 209, 191, 172, 194, 196, 196, 236, 235, 229, 243, 264, 272,
237, 211, 180, 201, 204, 188, 235, 227, 234, 264, 302, 293, 259, 229,
203, 229, 242, 233, 267, 269, 270, 315, 364, 347, 312, 274, 237, 278,
284, 277, 317, 313, 318, 374, 413, 405, 355, 306, 271, 306, 315, 301,
356, 348, 355, 422, 465, 467, 404, 347, 305, 336, 340, 318, 362, 348,
363, 435, 491, 505, 404, 359, 310, 337, 360, 342, 406, 396, 420, 472,
548, 559, 463, 407, 362, 405, 417, 391, 419, 461, 472, 535, 622, 606,
508, 461, 390, 432]})
df['ds'] = pd.to_datetime(df['ds'])
fbprophet plot_components():
model = Prophet()
model.fit(df)
future = model.make_future_dataframe(12, 'm')
fc = model.predict(future)
model.plot_components(fc)
plt.show()
I understand your question to mean "How do we get the values used in the "yearly" plot above?
days = (pd.date_range(start='2017-01-01', periods=365) + pd.Timedelta(days=0))
df_y = model.seasonality_plot_df(days)
seas = model.predict_seasonal_components(df_y)
fig,ax = plt.subplots(2, 1, figsize=(8,6))
ax[0].plot(fc['ds'].dt.to_pydatetime(), fc['trend'])
ax[0].grid(alpha=0.5)
ax[0].set_xlabel('ds')
ax[1].set_ylabel('trend')
ax[1].plot(df_y['ds'].dt.to_pydatetime(), seas['yearly'], ls='-', c='#0072B2')
ax[1].set_xlabel('Day of year')
ax[1].set_ylabel('yearly')
ax[1].grid(alpha=0.5)
plt.show()
Plot results:
How to obtain the values for yearly only?
The X values are an arbitrary yearly time period (basically). The y values use functions seasonality_plot_df() and predict_seasonal_components() to predict daily seasonality for a year time-span. You retrieve these values by looking in seas['yearly'].
There is a simple solution in the current version of the library. You can use from the predicted model fc. What you want for the value of yearly can be found with fc['yearly'] without using the functions in the above solution.
Moreover, if you want all the other components like trend, you can use fc['trend'].
I wrote a script in Python 3.5.2 and compiled it to a binary on Mac which works fine.
I then compiled the script on my Win 7 machine pyinstaller --onefile script.py. There were no errors during the compilation, however its execution fails.
Below is the full traceback.
Traceback (most recent call last):
File "site-packages\requests\packages\__init__.py", line 27, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\packages\urllib3\__init__.py", line 8, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\packages\urllib3\connectionpool.py", line 28, in <module>
File "site-packages\requests\packages\urllib3\packages\six.py", line 92, in __get__
File "site-packages\requests\packages\urllib3\packages\six.py", line 115, in _resolve
File "site-packages\requests\packages\urllib3\packages\six.py", line 82, in _import_module
ImportError: No module named 'queue'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "myscript.py", line 5, in <module>
import support
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "support.py", line 1, in <module>
import requests
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\__init__.py", line 63, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\utils.py", line 24, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\_internal_utils.py", line 11, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\compat.py", line 11, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\packages\__init__.py", line 29, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\urllib3\__init__.py", line 8, in <module>
File "c:\users\support\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\loader
\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\urllib3\connectionpool.py", line 28, in <module>
File "site-packages\urllib3\packages\six.py", line 92, in __get__
File "site-packages\urllib3\packages\six.py", line 115, in _resolve
File "site-packages\urllib3\packages\six.py", line 82, in _import_module
ImportError: No module named 'queue'
Failed to execute script myscript
I don't know what's wrong.
Sometimes,decode errors were found.
For example: GBK cann't decode.some special code : .\?-_... .Check your code!
numbers = [
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
743, 527]
count=0
while numbers(count)==527:
print(numbers(count))
count+=1
may in know what is the error in above code?
what is meant by "'list' object is not callable"
please correct the code
thanks.
numbers(count) replace on numbers[count]
count=0
while numbers[count]!=527:
print(numbers(count))
count+=1
If you want print all numbers except last:
for item in numbers[0:-1]:
print(item)
while numbers(count)==527: means that numbers is interpreted as a function with one argument, count. numbers is actually a list object, so when the interpreter tries to call the 'function' it will return the error you're seeing.
You need to use [] for indexing and slicing.
Your revised code would look like this:
numbers = [
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
743, 527]
count=0
while numbers[count]!=527:
print(numbers[count])
count+=1
This will print every item in numbers up until you get to the first instance of 527.