Converting a string of numbers to hex and back to dec pandas python
Question: I currently have a string of values which I retrieved after filtering through
data from a csv file. ultimately I had to do some filtering of the data but I
have the same numbers as a list, dataframe, or array. I just need to take the
numbers in the string and convert them to hex and then take the first 8
numbers of the hex and convert that to dec for each element in the string.
Lastly I also need to convert the last 8 of the same hex and then to dec as
well for each value in the string.

I cannot provide a snippet because it is sensitive data, but here is an
example.

I basically have something like this

    
    
    >>> list_A
    
    [52894036, 78893201, 45790373]
    

If I convert it to a dataframe and call `df.dtypes`, it says `dtype: object`
and I can convert the values of Column A to bool, int, or string, but the
dtype is always an object.

It does not matter whether it is a function, or just a simple loop. I have
been trying many methods and am unable to attain the results I need. But
ultimately the data is taken from different csv files and will never be the
same values or list size.


Answer: I'm not completely following your question, but this ought to cover most of
what you're trying to do. I'll do it in pandas since you seem to be doing it
that way, but as far as this question itself is concerned you could do it just
as easily with standard python.

    
    
    import pandas as pd
    df=pd.DataFrame({ 'a':[52894036999, 78893201999, 45790373999] })
    df['b'] = df['a'].apply( hex )
    df['c'] = df['b'].str[:10]
    df['d'] = df['c'].apply( lambda x: int(x,base=0) )
    
    df
                 a              b           c           d
    0  52894036999   0xc50baf407L  0xc50baf40  3305877312
    1  78893201999  0x125e66ba4fL  0x125e66ba   308176570
    2  45790373999   0xaa951a86fL  0xaa951a86  2861898374
    

Note that pandas basically has 2 main dtypes: numbers (ints or floats) and
objects. Objects can be anything, including strings.

    
    
    df.dtypes
    
    a     int64
    b    object
    c    object
    d     int64
    

Sometimes it can be more informative to check the type of the individual
elements of a column, rather than the dtype of the whole column. Here we'll
look at the first row and you can see that the middle two columns are strings.

    
    
    for col in df.columns:
        print( type(df[col].iloc[0]) )
    
    <type 'numpy.int64'>
    <type 'str'>
    <type 'str'>
    <type 'numpy.int64'>
    

