All Questions
2,440
questions
2
votes
1
answer
44
views
Casting RDD to a different type (from float64 to double)
I have a code like below, which uses pyspark.
test_truth_value = RDD.
test_predictor_rdd = RDD.
valuesAndPred = test_truth_value.zip(lasso_model.predict(test_predictor_rdd)).map(lambda x: ((x[0]), (x[...
2
votes
1
answer
39
views
Wrapped functions of a Python module raise TypeError
I am currently trying to replace a module in a large code base in a certain condition and to figure out when any function of this module is called, I wrap each function/method in the module with a ...
0
votes
2
answers
56
views
How to fix column with numeric values that is taken as a string field because of empty strings in Pandas dataframe?
I have a df with some columns that are supposed to be numeric fields. However, there are empty strings existing in these columns, which leads to their data being incorrectly assigned as 'object'. How ...
1
vote
1
answer
95
views
NumPy array size and performance differences for int8 vs bool dtype
I am trying to use numpy's nbytes attribute to examine the memory usage of arrays with different dtype. I noticed the following:
>>> np.zeros(1024, dtype='int64').nbytes / 1024 # in kB
8.0
...
0
votes
2
answers
57
views
Fail to convert float 64 to float 32 in python [duplicate]
I tried to convert the data from data type float 64 to float 32. I used both pandas method and pytorch but no avail. Dataset are from kaggle titanic project. The code is the following:
from torch ...
1
vote
1
answer
35
views
More detailed info about data type that is common throughout a Series?
I have a dataframe column consisting entirely of a common type dict. Is there any way to query the Series type to reveal the common data type? It currently only tells me that it is an object, which ...
-3
votes
3
answers
85
views
Understanding the ‘cannot interpret ‘20’ as a data type’ error in np.dtype(20) [closed]
I’ve coded in python before for my university course but never really understood it- I’m trying to do that now.
I’m trying to understand why the following code gives an error:
import numpy as np
np....
0
votes
1
answer
80
views
Formatting specific rows in Pandas Dataframe with string formatting and heatmap
Here I have a code for a function that creates a formatted table.It currently works but I want to optimise it considering "Setting an item of incompatible dtype is deprecated and will raise an ...
0
votes
0
answers
31
views
How to create PySpark column of dictionary type with value not of any fixed type?
This is a pyspark code. I am creating two columns, 'item' and 'properties'.
'item' column is of String type and 'properties' column is of dictionary type where the type of key is String but the type ...
0
votes
0
answers
32
views
Ansible running a query extracting a `time without time zone` object raises `TypeError: Value of unknown type: <type 'datetime.date'>`
I am writing an ansible playbook.
I have the following task
- name: query on server_app - look for items_invoiced
community.postgresql.postgresql_query:
login_host: '{{ db_host }}'
...
0
votes
2
answers
132
views
ValueError: Exception encountered when calling PositionalEmbedding.call()
I am running Neural machine translation with a Transformer and Keras. https://www.tensorflow.org/text/tutorials/transformer
pt is an tokenized vectors of size (64, 79). For the following class, ...
2
votes
1
answer
52
views
Are there good reason to accept float but not int in a function in Python?
In a big library, I had a 'bug' because a function which accept only float but not int
def foo(penalty: float):
if not isinstance(penalty, float):
raise ValueError(f"`penalty` has to be ...
0
votes
1
answer
50
views
Can't define a global variable that has a type within a function
I'm trying to create a function that reloads a global bank:
import json
type Bank = dict[str, dict[str: int | float]]
def get_ball() -> None:
"""
_summary_
Reloads the ...
1
vote
1
answer
180
views
Config Sweetviz to force analyze object-type column without conversion
Consider the following short dataframe example:
df = pd.DataFrame({'column1': [2, 4, 8, 0],
'column2': [2, 0, 0, 0],
'column3': ["test", 2, 1, 8]})
df....
0
votes
2
answers
35
views
Differentiate when printing with python type() and two different types have same name but different subclass [duplicate]
I have two different classes with same Subclass name and printing it out using type() gives me same output.
from enum import IntEnum
class Car:
class Manufacturer(IntEnum):
BMW = 0
...