convert dask series into dask dataframe - python-3.5

I would like to know how to convert a dask.dataframe.core.Series to a dask dataframe.
I have:
type(card_id_pur_freq)
output:
dask.dataframe.core.Series
I tried:
card_id_pur_freq = dd.DataFrame(card_id_pur_freq)
output:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-36-bd6cdab52455> in <module>
----> 1 card_id_pur_freq = dd.DataFrame(card_id_pur_freq)
TypeError: __init__() missing 3 required positional arguments: 'name', 'meta', and 'divisions'
I would like to know how to convert a dask series into a dataframe.
Please let me know. #MRocklin
Thanks
Michael

Try the .to_frame() method
df = s.to_frame()

Related

enquiry on uniformly distributed random numbers using python

please how can I randomly generate 5,000 integers uniformly distributed in [1, 100] and find the mean using python. I tried the function np.random.randint(100, size=5000), but I got below error message while trying to get the mean.
Traceback (most recent call last):
File "", line 1, in
TypeError: 'numpy.ndarray' object is not callable
You can use random.randint:
import numpy as np
r=np.random.randint(0,100,5000)
Then use mean to find the mean of that:
>>> np.mean(r)
49.4686
You can also use the array method of mean():
>>> r.mean()
49.4686
you can use this:
np.random.randint(1, 100, size=1000).mean()

NameError: name 'Series' is not defined while using Jupyter Lab

I am new to python. I am using anaconda and trying to write some python code in it. I have written 2 lines of code in which I am trying to create a Series data from a dictonary
Hi #ApurvG there is no function called Series in native python.
If your question is about pandas series you can do it like this:
import pandas as pd
dictionary={'apurb':400}
series = pd.Series(dictionary)
Jupyter:-
salary = {'John': 5000, 'Rob': 6000, 'Wills':7500, 'Ashu': 5500}
salary
se3 = Series(salary)
NameError Traceback (most recent call last)
C:\Users\ADMINI~1\AppData\Local\Temp/ipykernel_13716/1803553183.py in
----> 1 se3 = Series(salary)
NameError: name 'Series' is not defined
import pandas as pd
se4 = pd.Series(salary)
se4
John 5000
Rob 6000
Wills 7500
Ashu 5500
dtype: int64

Converting timeseries into datetime format in python

I have the column of dates called 'Activity_Period' in this format '200507' which means July 2005 and I want to convert it to datetime format of ('Y'-'m') in python.
I tried to use the datetime.strp however it shows that the input has to be a string and not a series.
df.Activity_Period=datetime.strptime(df.Activity_Period, '%Y-%m')
The following is the error I get
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-ac32eb324a0b> in <module>
----> 1 df.Activity_Period=datetime.strptime(df.Activity_Period, '%Y-%m')
TypeError: strptime() argument 1 must be str, not Series
import datetime as dt
import pandas as pd
#simple example
timestamp = '200507'
result = dt.datetime.strptime(timestamp, '%Y%m')
print(result)
#Example using pandas series
series = pd.Series(['200507', '200508', '200509', '200510'])
series = pd.to_datetime(series, format='%Y%m')
print(series)
#for your DF
df['Activity_Period'] = pd.to_datetime(df['Activity_Period'], format='%Y%m')

Tensorflow TypeError: 'numpy.ndarray' object is not callable

while trying to predict the model i am getting this numpy.ndarray error .it might be the returning statement of the prepare function. what can be possibly done to get rid of this error .
import cv2
import tensorflow as tf
CATEGORIES = ["Dog", "Cat"]
def prepare(filepath):
IMG_SIZE = 50 # 50 in txt-based
img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
model = tf.keras.models.load_model("64x3-CNN.model")
prediction = model.predict([prepare('dog.jpg')])
print(prediction) # will be a list in a list.
tried to give the full path still the same error persist.
TypeError Traceback (most recent call last)
<ipython-input-45-f9de27e9ff1e> in <module>
15
16 prediction = model.predict([prepare('dog.jpg')])
---> 17 print(prediction) # will be a list in a list.
18 print(CATEGORIES[int(prediction[0][0])])
TypeError: 'numpy.ndarray' object is not callable
Not sure what the rest of your code looks like. But if you use 'print' as a variable in Python 3 you can get this error:
import numpy as np
x = np.zeros((2,2))
print = np.ones((2,2))
print(x)
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'numpy.ndarray' object is not callable
This type of errors mostly occurs when trying to print an array instead of simple strings or single variable numbers, so I would recommend you to change:
17 print(prediction) # will be a list in a list.
18 print(CATEGORIES[int(prediction[0][0])])
Then you would get:
17 print(str(prediction)) # will be a list in a list.
18 print(str(CATEGORIES[int(prediction[0][0])]))

AttributeError: 'NoneType' object has no attribute 'Mrc'

I am getting an error for the following code.
Can someone please tell me where I am going wrong?
p.s. I have given the path correctly for.mrcfile
import numpy
import Mrc
a = Mrc.bindFile('somefile.mrc')
# a is a NumPy array with the image data memory mapped from
# somefile.mrc. You can use it directly with any function
# that will take a NumPy array.
hist = numpy.histogram(a, bins=200)
# a.Mrc is an instances of the Mrc class. One thing
# you can do with that class is print out key information from the header.
a.Mrc.info()
# Use a.Mrc.hdr to access the MRC header fields.
wavelength0_nm = a.Mrc.hdr.wave[0]
AttributeError Traceback (most recent call last)
in ()
3 a = Mrc.bindFile('/home/smitha/deep-image-prior/data/Falcon_2015_05_14-20_42_18.mrc')
4 hist = numpy.histogram(a, bins=200)
----> 5 a.Mrc.info()
6 wavelength0_nm = a.Mrc.hdr.wave[0]
7
AttributeError: 'NoneType' object has no attribute 'Mrc'

Resources