logo
down
shadow

Replacing integers with NaN results in the entire column becoming float dtype


Replacing integers with NaN results in the entire column becoming float dtype

By : AM Gorman
Date : November 23 2020, 03:01 PM
To fix this issue First, I did , Because of this:
code :
type(np.nan)
# float
b = b.astype('Int32')
b

   0  1  2  3    4    5
0  6  5  4  3    2  NaN
1  1  2  3  4    5    6
2  3  4  5  6  NaN  NaN

b.dtypes

0    Int32
1    Int32
2    Int32
3    Int32
4    Int32
5    Int32
dtype: object
u = df.select_dtypes(float)
b[u.columns] = u.astype(object)
b

   0  1  2  3    4    5
0  6  5  4  3    2  NaN
1  1  2  3  4    5    6
2  3  4  5  6  NaN  NaN

print(b.dtypes)
0     int64
1     int64
2     int64
3     int64
4    object
5    object
dtype: object


Share : facebook icon twitter icon
How to convert from a dtype('o') to a dtype(float) in numpy?

How to convert from a dtype('o') to a dtype(float) in numpy?


By : TheCoolestTaco
Date : March 29 2020, 07:55 AM
Hope this helps (from the helpful comments)
Check the length of those sublists. If they are all the same I'd expect a 2d array; but if they differ (most 3, but some 0, 2,4 etc) then the best it can do is give you a 1d array of 'objects' - the lists.
Assigning dtype value using array.dtype = <data type> in NumPy arrays gives ambiguous results

Assigning dtype value using array.dtype = <data type> in NumPy arrays gives ambiguous results


By : Dilwar Hussain
Date : March 29 2020, 07:55 AM
wish helps you Floats and integers (numpy.float64s and numpy.int64s) are represented differently in memory. The value 42 stored in these different types corresponds to a different bit pattern in memory.
When you're reassigning the dtype attribute of an array, you keep the underlying data unchanged, and you're telling numpy to interpret that pattern of bits in a new way. Since the interpretation now doesn't match the original definition of the data, you end up with gibberish (meaningless numbers).
code :
>>> import numpy as np
>>> arr = np.random.rand(3)
>>> arr.dtype
dtype('float64')
>>> arr
array([ 0.7258989 ,  0.56473195,  0.20885672])
>>> arr.data
<memory at 0x7f10d7061288>
>>> arr.dtype = np.int64
>>> arr.data
<memory at 0x7f10d7061348>
>>> arr
array([4604713535589390862, 4603261872765946451, 4596692876638008676])
>>> arr = np.random.rand(3)*10
>>> arr
array([ 3.59591191,  1.21786042,  6.42272461])
>>> arr.astype(np.int64)
array([3, 1, 6])
>>> arr = np.random.rand(3)
>>> arr.shape
(3,)
>>> arr.dtype
dtype('float64')
>>> arr.dtype = np.float32
>>> arr.shape
(6,)
>>> arr
array([  4.00690371e+35,   1.87285304e+00,   8.62005305e+13,
         1.33751166e+00,   7.17894062e+30,   1.81315207e+00], dtype=float32)
>>> arr = np.array([255,255],dtype=np.uint8)
>>> arr.dtype = np.uint16
>>> arr
array([65535], dtype=uint16)
Replacing integers in a dataframe column that's a list of integer vectors (not just single integers) with character stri

Replacing integers in a dataframe column that's a list of integer vectors (not just single integers) with character stri


By : user2980074
Date : March 29 2020, 07:55 AM
may help you . I suggest creating a "lookup dictionary" of sorts, and lapply across each of the ids:
code :
example_concord_idx <- setNames(as.character(example_concord$last_names),
                                example_concord$player_ids)
example_concord_idx
#            1            2            3            4            5            6 
#    "Rapinoe"    "Wambach"     "Naeher"     "Morgan" "Dahlkemper"      "Mitts" 
#            7 
#   "O'Reilly" 

starting_dataframe$result <- 
  lapply(starting_dataframe$player_indices,
         function(a) example_concord_idx[a])
starting_dataframe
#   first_names player_indices              result
# 1       Megan              1             Rapinoe
# 2        Abby           2, 5 Wambach, Dahlkemper
# 3      Alyssa              3              Naeher
# 4        Alex              4              Morgan
# 5     Heather           6, 7     Mitts, O'Reilly
Map(`[`, list(example_concord_idx), starting_dataframe$player_indices)
error raised by tensorflow.map_fn: TensorArray dtype is double but Op is trying to write dtype float.

error raised by tensorflow.map_fn: TensorArray dtype is double but Op is trying to write dtype float.


By : Chi Zhang
Date : March 29 2020, 07:55 AM
hop of those help? The problem is that lang_model returns float32s and map_fn says it returns float64s. One way to fix the problem is to cast the function's outputs as float64s:
code :
prob_labels = tf.cast(tf.multiply(W4,S3), tf.float64)
norm_const = tf.cast(tf.matmul(W4,S3, transpose_b=True), tf.float64)
Convert object dtype column to float or int

Convert object dtype column to float or int


By : sam
Date : October 07 2020, 09:00 PM
like below fixes the issue
There is a helper class in scikit-learn which implements this nicely, it's called sklearn.preprocessing.LabelEncoder
Related Posts Related Posts :
  • How to calculate each single element of a numpy array based on conditions
  • How do I change the width of Jupyter notebook's cell's left part?
  • Measure distance between lat/lon coordinates and utm coordinates
  • Installing megam for NLTK on Windows
  • filter dataframe on each value of a samn column have a specific value of another column in Panda\Python
  • Threading with pubsub throwing AssertionError: 'callableObj is not callable' in wxPython
  • Get grouped data from 2 dataframes with condition
  • How can I import all of sklearns regressors
  • How to take all elements except the first k
  • Whats wrong with my iteration list of lists from csv
  • Tensorflow Estimator API save image summary in eval mode
  • How to Pack with PyQt - how to make QFrame/Layout adapt to content
  • How do I get certain Time Range in Python
  • python doubly linked list - insertAfter node
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org