parameter gather is not used - python

import pandas as pd
import os
import time
from datetime import datetime
path = "/Users/tommasomasaracchio/Documents/pythonfolder"
def key_stats(gather="Total Deb/Equity (mrg)"):
statspath = path + '/KeyStats'
stock_list = [x[0] for x in os.walk(statspath)]
print(stock_list)
key_stats()
I thought the problem was gather but it seems not to be the case.
the terminal tells me this, and I don't really understand it
tommaso desktop % python programma.py
hello world
Traceback (most recent call last):
File "/Users/tommasomasaracchio/Desktop/programma.py", line 2, in <module>
import pandas as pd
File "/Users/tommasomasaracchio/opt/anaconda3/lib/python3.9/site-packages/pandas/__init__.py", line 179, in <module>
import pandas.testing
File "/Users/tommasomasaracchio/opt/anaconda3/lib/python3.9/site-packages/pandas/testing.py", line 6, in <module>
from pandas._testing import (
File "/Users/tommasomasaracchio/opt/anaconda3/lib/python3.9/site-packages/pandas/_testing/__init__.py", line 58, in <module>
from pandas._testing._io import ( # noqa:F401
File "/Users/tommasomasaracchio/opt/anaconda3/lib/python3.9/site-packages/pandas/_testing/_io.py", line 22, in <module>
from pandas._testing._random import rands
File "/Users/tommasomasaracchio/opt/anaconda3/lib/python3.9/site-packages/pandas/_testing/_random.py", line 10, in <module>
RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
AttributeError: module 'string' has no attribute 'ascii_letters'

Related

Using PyTorch to utilise DBpedia - keyerror: content disposition

I am currently trying to download data from the torchtext.datasets module and it is not working.
Here is the following code that I have written (taken from https://analyticsindiamag.com/multi-class-text-classification-in-pytorch-using-torchtext/):
import torch
import torchtext
from torchtext.datasets import text_classification
import os
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
import time
from torch.utils.data.dataset import random_split
import re
from torchtext.data.utils import ngrams_iterator
from torchtext.data.utils import get_tokenizer
ngrams = 2
batch_size = 16
if not os.path.isdir('./.data'):
os.mkdir('./.data')
train_dataset, test_dataset = text_classification.DATASETS['DBpedia'](root='./.data', ngrams=ngrams, vocab=None)
It produces the following error:
Traceback (most recent call last):
File "/Users/aidanpayne/Desktop/Scripts/Python/Neural Networks/text_classification_model.py", line 19, in <module>
train_dataset, test_dataset = text_classification.DATASETS['DBpedia'](root='./.data', ngrams=ngrams, vocab=None)
File "/Users/aidanpayne/opt/anaconda3/lib/python3.8/site-packages/torchtext/datasets/text_classification.py", line 237, in DBpedia
return _setup_datasets(*(("DBpedia",) + args), **kwargs)
File "/Users/aidanpayne/opt/anaconda3/lib/python3.8/site-packages/torchtext/datasets/text_classification.py", line 117, in _setup_datasets
dataset_tar = download_from_url(URLS[dataset_name], root=root)
File "/Users/aidanpayne/opt/anaconda3/lib/python3.8/site-packages/torchtext/utils.py", line 100, in download_from_url
return _process_response(response, root, filename)
File "/Users/aidanpayne/opt/anaconda3/lib/python3.8/site-packages/torchtext/utils.py", line 53, in _process_response
d = r.headers['content-disposition']
File "/Users/aidanpayne/opt/anaconda3/lib/python3.8/site-packages/requests/structures.py", line 54, in __getitem__
return self._store[key.lower()][1]
KeyError: 'content-disposition'
If anyone can help, that would be great!

Geopandas not working after importing a file from a different directory

I am trying to make a map in python using shapefiles I have downloaded from bbike.org. Here is my code:
import geopandas as gpd
import os
import sys
import matplotlib.pyplot as plt
bos_files_list = ['buildings.shx', 'landuse.shx', 'natural.shx', 'places.shx', 'points.shx', 'railways.shx', 'roads.shx']
cur_path = os.path.dirname(__file__)
def maps_of_bos(files):
for x in range(len(files)):
os.chdir(f'location/of/file')
f = open(f'{files[x]}', 'r')
gpd.read_file(f)
z = maps_of_bos(bos_files_list)
z.plot()
plt.show()
However, my error output is as follows:
Traceback (most recent call last):
File "test.py", line 16, in <module>
z = maps_of_bos(bos_files_list)
File "test.py", line 13, in maps_of_bos
gpd.read_file(f)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopandas/io/f
ile.py", line 76, in read_file
with reader(path_or_bytes, **kwargs) as features:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 113, in
__enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/fiona/__init__
.py", line 206, in fp_reader
dataset = memfile.open()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/fiona/io.py",
line 63, in open
return Collection(vsi_path, 'w', crs=crs, driver=driver,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/fiona/collecti
on.py", line 126, in __init__
raise DriverError("no driver")
fiona.errors.DriverError: no driver
I am relatively new to python, and don't really understand my error. can someone please help me?
According to the docs read_file should take the path to the file not an object.
gpd.read_file(f'{files[x]}')
you dont need
f = open(f'{files[x]}', 'r')

AttributeError: function 'GEOSCovers' not found

I have install shapely on my pc win 64 bit python 2.7. When i write import shapely it works fine. But the above error comes in the following code:
import numpy as np
from scipy.spatial import Voronoi, voronoi_plot_2d
import shapely.geometry
import shapely.ops
points = np.random.random((10, 2))
vor = Voronoi(points)
voronoi_plot_2d(vor)
lines = [
shapely.geometry.LineString(vor.vertices[line])
for line in vor.ridge_vertices
if -1 not in line
]
for poly in shapely.ops.polygonize(lines):
print poly
Error:
Traceback (most recent call last):
File "C:\Users\Shikha\Desktop\vorn.py", line 3, in <module>
import shapely.geometry
File "C:\Python27\lib\site-packages\shapely-1.5.9-py2.7.egg\shapely\geometry\__init__.py", line 4, in <module>
from .base import CAP_STYLE, JOIN_STYLE
File "C:\Python27\lib\site-packages\shapely-1.5.9-py2.7.egg\shapely\geometry\base.py", line 9, in <module>
from shapely.coords import CoordinateSequence
File "C:\Python27\lib\site-packages\shapely-1.5.9-py2.7.egg\shapely\coords.py", line 8, in <module>
from shapely.geos import lgeos
File "C:\Python27\lib\site-packages\shapely-1.5.9-py2.7.egg\shapely\geos.py", line 145, in <module>
prototype(_lgeos, geos_version)
File "C:\Python27\lib\site-packages\shapely-1.5.9-py2.7.egg\shapely\ctypes_declarations.py", line 252, in prototype
lgeos.GEOSCovers.restype = c_byte
File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'GEOSCovers' not found

from sympy import Plot fail

I am using three different ways to import Plot function. All fail.
1:
from sympy import *
if __name__ == '__main__':
pp1,pp2,el1,el2=insline(0,0,4,0,1.5,1,1.5,1)
print pp1.evalf(),pp2.evalf()
p=Plot()
p[0]=el1
p[1]=el2
p[2]=Segment(pp1,pp2)
p.show()
Shows:
Traceback (most recent call last):
File "C:\Users\Erdong\workspace\Gungeo\src\gungeo.py", line 39, in <module>
p=Plot()
NameError: name 'Plot' is not defined
2:
from sympy import Point, Ellipse, intersection, Segment,plot
import math
def
...
if __name__ == '__main__':
pp1,pp2,el1,el2=insline(0,0,4,0,1.5,1,1.5,1)
print pp1.evalf(),pp2.evalf()
p=plot.Plot()
p[0]=el1
p[1]=el2
p[2]=Segment(pp1,pp2)
p.show()
Shows:
Traceback (most recent call last):
File "C:\Users\Erdong\workspace\Gungeo\src\gungeo.py", line 39, in <module>
p=plot.Plot()
AttributeError: 'function' object has no attribute 'Plot'
3.
from sympy import Plot
Shows:
Traceback (most recent call last):
File "E:\Project\Build up\programming\learn\learn.py", line 7, in <module>
from sympy import Plot
ImportError: cannot import name Plot
Please help how to import Plot from sympy-0.7.6.
I also tried:
from sympy.plotting.pygletplot import PygletPlot as Plot
But got error also:
{
Traceback (most recent call last):
File "C:\Users\Erdong\workspace\Gungeo\src\gungeo.py", line 92, in
p=Plot(el1)
File "C:\Python27\lib\site-packages\sympy\plotting\pygletplot__init__.py", line 139, in PygletPlot
import plot
File "C:\Python27\lib\site-packages\sympy\plotting\pygletplot\plot.py", line 16, in
from plot_axes import PlotAxes
File "C:\Python27\lib\site-packages\sympy\plotting\pygletplot\plot_axes.py", line 7, in
from util import strided_range, billboard_matrix
File "C:\Python27\lib\site-packages\sympy\plotting\pygletplot\util.py", line 8, in
def get_model_matrix(array_type=c_float, glGetMethod=glGetFloatv):
NameError: name 'c_float' is not defined
}
Have a look at http://docs.sympy.org/latest/modules/plotting.html. It should be
from sympy import symbols
from sympy.plotting import plot
x = symbols('x')
p = plot(x)
Maybe you want the old Plot that uses pyglet:
from sympy.plotting.pygletplot import PygletPlot as Plot

Mistake in Spyder setting

I have a little problem in using Spyder to run a python program:
This is my program:
from PySide.QtGui import QApplication
from pyoppinet.helper.correlation_manager import *
import pyoppinet.network as nt
import numpy as np
from pyoppinet.node import node
from pyoppinet.GUI import network_view as nw
from pyoppinet.pipe.flowline import Flowline
network = nt.PipeLineNetwork(1000.2000)
source1 = node.Source(10,200)
source1.name = 'source1'
source2 = node.Source(150,500)
source2.name = 'source2'
source3 = node.Source(200,400)
source3.name = 'source3'
junction1 =node.Junction(150,600)
junction1.name = 'junction'
sink =node.Sink(300,800)
sink.name = 'sink'
for n in [source1,source2,source3,junction1,sink]:
network.add_node(n)
fl1=Flowline(source1,junction1)
fl2=Flowline(junction1,sink)
fl3=Flowline(source2,sink)
fl4=Flowline(source2,junction1)
fl5=Flowline(source3,sink)
fl6=Flowline(source3,junction1)
for n in [fl1,fl2,fl3,fl4,fl5,fl6]:
network.add_flowline(n)
print [n.name for n in network.get_nodes()]
print 'topological sort', [n.name for n in network.topological_sort()]
a=QApplication([])
view=nw.PipeLineNetworkView(network)
view.show()
a.exec_()
These two rows:
from pyoppinet.helper.correlation_manager import *
import numpy as np
are error.
And the error is:
Traceback (most recent call last):
File "D:\program oppinet\latihan\latihan.py", line 9, in <module>
from pyoppinet.helper.correlation_manager import *
File "D:\program oppinet\pyoppinet\__init__.py", line 1, in <module>
import GUI
File "D:\program oppinet\pyoppinet\GUI\__init__.py", line 7, in <module>
"""
File "D:\program oppinet\pyoppinet\GUI\viewmodelbase.py", line 1, in <module>
File "D:\program oppinet\pyoppinet\GUI\framework\__init__.py", line 3, in <module>
# Copyright © 2011 Pierre Raybaut
File "D:\program oppinet\pyoppinet\GUI\framework\GUI_helper.py", line 1, in <module>
File "D:\program oppinet\pyoppinet\helper\__init__.py", line 3, in <module>
# Copyright © 2011 Pierre Raybaut
File "D:\program oppinet\pyoppinet\helper\UnitInfo.py", line 2, in <module>
File "D:\program oppinet\pyoppinet\C_API\converter.py", line 26, in <module>
File "D:\program oppinet\pyoppinet\C_API\converter.py", line 18, inswig_import_helper
ImportError: No module named _converter
I believe that the error is caused by the setting in spyder, maybe in tools or something.
Could I change some setting in spyder to fix this problem?

Categories