module 'pandas' has no attribute 'series' - python-3.x

i got this error while running this code
import numpy as np
import pandas as pd
labels = ['a','b','c']
my_list = [10,20,30]
arr = np.array(my_list)
d = {'a':10,'b':20,'c':30}
pd.series(data = my_list)
full error msg
AttributeError Traceback (most recent call last)
<ipython-input-10-494578c29940> in <module>
----> 1 pd.series(data = my_list)
F:\New folder (8)\lib\site-packages\pandas\__init__.py in __getattr__(name)
260 return _SparseArray
261
--> 262 raise AttributeError(f"module 'pandas' has no attribute '{name}'")
263
264
AttributeError: module 'pandas' has no attribute 'series'

Series is a Pandas class, so it starts with a capital letter. The below should work.
pd.Series(data = my_list)

Related

AttributeError: module 'ee' has no attribute 'Reducer'

I'm learning GEE recently with accessing VPN but met error as show below:
#######################################################
import ee
import geemap
import os
geemap.set_proxy(port=7890)
os.environ['HTTP_PROXY'] = 'http://127.0.0.1:7890'
os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:7890'
Map = geemap.Map()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [5], line 7
5 os.environ['HTTP_PROXY'] = 'http://127.0.0.1:7890'
6 os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:7890'
----> 7 Map = geemap.Map()
File ~\anaconda3\envs\gee\lib\site-packages\geemap\geemap.py:173, in
Map.__init__(self, **kwargs)
171 self.roi_end = False
172 if kwargs["ee_initialize"]:
--> 173 self.roi_reducer = ee.Reducer.mean()
174 self.roi_reducer_scale = None
176 # List for storing pixel values and locations based on user-drawn
geometries.
AttributeError: module 'ee' has no attribute 'Reducer'
##############################################################
I checked too many answers through forum but nothing work. Is there anyone who knows the reason? really appreciate it!

"TypeError: float() argument must be a string or a number, not 'FreeRV' " in pymc3

I am stuck in the following error in pymc3 and at a loss.
TypeError: float() argument must be a string or a number, not 'FreeRV'
The below is my code. I pick up this code from here. (Sorry, this is Japanese). However it does not work in my environment:
Google Colab, Python: 3.7.13, pymc3: 3.11.4
import numpy as np
import matplotlib
import matplotlib.pylab as plt
%matplotlib inline
from tqdm import tqdm
import pymc3 as pm
# generate time-series data
np.random.seed(0)
y = np.cumsum(np.random.normal(size=100))
# Infer parameters in time-series data
N = len(y)
T = 1000
with pm.Model() as model:
muZero = pm.Normal(name='muZero', mu=0.0, tau=1.0)
sigmaW = pm.InverseGamma(name='sigmaW', alpha=1.0, beta=1.0)
mu = [0]*N
mu[0] = pm.Normal(name='mu0', mu=muZero, tau=1/sigmaW)
for n in range(1, N):
mu[n] = pm.Normal(name='mu'+str(n), mu=mu[n-1], tau=1/sigmaW)
sigmaV = pm.InverseGamma(name='sigmaV', alpha=1.0, beta=1.0)
y_pre = pm.Normal('y_pre', mu=mu, tau=1/sigmaV, observed=y) # I got error here
start = pm.find_MAP()
step = pm.NUTS()
trace = pm.sample(T, step, start=start)
Here is the full discription of my error.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pymc3/theanof.py in floatX(X)
82 try:
---> 83 return X.astype(theano.config.floatX)
84 except AttributeError:
AttributeError: 'list' object has no attribute 'astype'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
TypeError: float() argument must be a string or a number, not 'FreeRV'
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
4 frames
<ipython-input-30-c3709f545993> in <module>()
26
27 sigmaV = pm.InverseGamma(name='sigmaV', alpha=1.0, beta=1.0)
---> 28 y_pre = pm.Normal('y_pre', mu=mu, tau=1/sigmaV, observed=y) # I got error here
29 start = pm.find_MAP()
30 step = pm.NUTS()
/usr/local/lib/python3.7/dist-packages/pymc3/distributions/distribution.py in __new__(cls, name, *args, **kwargs)
119 dist = cls.dist(*args, **kwargs, shape=shape)
120 else:
--> 121 dist = cls.dist(*args, **kwargs)
122 return model.Var(name, dist, data, total_size, dims=dims)
123
/usr/local/lib/python3.7/dist-packages/pymc3/distributions/distribution.py in dist(cls, *args, **kwargs)
128 def dist(cls, *args, **kwargs):
129 dist = object.__new__(cls)
--> 130 dist.__init__(*args, **kwargs)
131 return dist
132
/usr/local/lib/python3.7/dist-packages/pymc3/distributions/continuous.py in __init__(self, mu, sigma, tau, sd, **kwargs)
485 self.tau = tt.as_tensor_variable(tau)
486
--> 487 self.mean = self.median = self.mode = self.mu = mu = tt.as_tensor_variable(floatX(mu))
488 self.variance = 1.0 / self.tau
489
/usr/local/lib/python3.7/dist-packages/pymc3/theanof.py in floatX(X)
84 except AttributeError:
85 # Scalar passed
---> 86 return np.asarray(X, dtype=theano.config.floatX)
87
88
ValueError: setting an array element with a sequence.

AttributeError: 'DataFrame' object has no attribute 'droplevel' in pandas

I am getting a strange (to my understanding) message when I try to drop a level from a multi-indexed pandas dataframe.
For a reproducible example:
toy.to_json()
'{"["ISRG","EPS_diluted"]":{"2004-12-31":0.33,"2005-01-28":0.33,"2005-03-31":0.25,"2005-04-01":0.25,"2005-04-29":0.25},"["DHR","EPS_diluted"]":{"2004-12-31":0.67,"2005-01-28":0.67,"2005-03-31":0.67,"2005-04-01":0.58,"2005-04-29":0.58},"["BDX","EPS_diluted"]":{"2004-12-31":0.75,"2005-01-28":0.75,"2005-03-31":0.72,"2005-04-01":0.72,"2005-04-29":0.72},"["SYK","EPS_diluted"]":{"2004-12-31":0.4,"2005-01-28":0.4,"2005-03-31":0.42,"2005-04-01":0.42,"2005-04-29":0.42},"["BSX","EPS_diluted"]":{"2004-12-31":0.35,"2005-01-28":0.35,"2005-03-31":0.42,"2005-04-01":0.42,"2005-04-29":0.42},"["BAX","EPS_diluted"]":{"2004-12-31":0.18,"2005-01-28":0.18,"2005-03-31":0.36,"2005-04-01":0.36,"2005-04-29":0.36},"["EW","EPS_diluted"]":{"2004-12-31":0.4,"2005-01-28":0.4,"2005-03-31":0.5,"2005-04-01":0.5,"2005-04-29":0.5},"["MDT","EPS_diluted"]":{"2004-12-31":0.44,"2005-01-28":0.45,"2005-03-31":0.45,"2005-04-01":0.45,"2005-04-29":0.16},"["ABT","EPS_diluted"]":{"2004-12-31":0.63,"2005-01-28":0.63,"2005-03-31":0.53,"2005-04-01":0.53,"2005-04-29":0.53}}'
toy.droplevel(level = 1, axis = 1)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-33-982eee5ba162> in <module>()
----> 1 toy.droplevel(level = 1, axis = 1)
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
4370 if self._info_axis._can_hold_identifiers_and_holds_name(name):
4371 return self[name]
-> 4372 return object.__getattribute__(self, name)
4373
4374 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'droplevel'
Problem is the use of an older pandas version, because if you check DataFrame.droplevel:
New in version 0.24.0.
The solution is to use MultiIndex.droplevel:
toy.columns = toy.columns.droplevel(level = 1)

Converting a generator into a list, but getting Error: '_io.TextIOWrapper' object has no attribute 'decode' (python 3.6.4)

I am working with a text in utf-8.
I want to tokenize it and then convert it into a list.
However I get the following error.
import nltk, jieba, re, os
with open('file.txt') as f:
tokenized_text = jieba.cut(f,cut_all=True)
type(tokenized_text)
generator
word_list = list(tokenized_text)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-16b25477c71d> in <module>()
----> 1 list(new)
~/anaconda3/lib/python3.6/site-packages/jieba/__init__.py in cut(self, sentence, cut_all, HMM)
280 - HMM: Whether to use the Hidden Markov Model.
281 '''
--> 282 sentence = strdecode(sentence)
283
284 if cut_all:
~/anaconda3/lib/python3.6/site-packages/jieba/_compat.py in strdecode(sentence)
35 if not isinstance(sentence, text_type):
36 try:
---> 37 sentence = sentence.decode('utf-8')
38 except UnicodeDecodeError:
39 sentence = sentence.decode('gbk', 'ignore')
AttributeError: '_io.TextIOWrapper' object has no attribute 'decode'
I understand the problem lies somewhere in the jieba package.
I also tried to change the code into
with open('file.txt') as f:
new = jieba.cut(f,cut_all=False)
but got the same result.
jieba.cut takes a string, not a file. This is explained in the readme.

module 'pyspark_csv' has no attribute 'csvToDataframe'

I am new to spark and facing an error while converting .csv file to dataframe. I am using pyspark_csv module for the conversion but gives an error saying "module 'pyspark_csv' has no attribute 'csvToDataframe".
here is my code:
import findspark
findspark.init()
findspark.find()
import pyspark
sc=pyspark.SparkContext(appName="myAppName")
sqlCtx = pyspark.SQLContext
#csv to dataframe
sc.addPyFile('/usr/spark-1.5.0/python/pyspark_csv.py')
sc.addPyFile('https://raw.githubusercontent.com/seahboonsiew/pyspark-csv/master/pyspark_csv.py')
import pyspark_csv as pycsv
#skipping the header
def skip_header(idx, iterator):
if(idx == 0):
next(iterator)
return iterator
#loading the dataset
data=sc.textFile('gdeltdata/20160427.CSV')
data_header = data.first()
data_body = data.mapPartitionsWithIndex(skip_header)
data_df = pycsv.csvToDataframe(sqlctx, data_body, sep=",", columns=data_header.split('\t'))
AttributeError Traceback (most recent call last)
<ipython-input-10-8e47cd9759e6> in <module>()
----> 1 data_df = pycsv.csvToDataframe(sqlctx, data_body, sep=",", columns=data_header.split('\t'))
AttributeError: module 'pyspark_csv' has no attribute 'csvToDataframe'
As mentioned in https://github.com/seahboonsiew/pyspark-csv
Please try using the following command:
csvToDataFrame
with Frame instead of frame

Resources