Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

pandas - Python TypeError: cannot convert the series to <class 'int'> when trying to do math on dataframe

I have a data frame that looks something like this:

defaultdict(<class 'list'>, {'XYF':             TimeUS           GyrX           GyrY           GyrZ         AccX  
0        207146570    0.000832914    0.001351716  -0.0004189798    -0.651183   
1        207186671    0.001962787    0.001242457  -0.0001859666   -0.6423497   
2        207226791   9.520243E-05    0.001076498  -0.0005664826   -0.6360412   
3        207246474   0.0001093059    0.001616917   0.0003615251   -0.6342875   
4        207286244    0.001412051   0.0007565815  -0.0003780428    -0.637755   


[103556 rows x 12 columns], 'DAR':           TimeUS RSSI RemRSSI TxBuf Noise RemNoise RxErrors Fixed
0      208046965  159     161    79    25       29        0     0
1      208047074  159     161    79    25       29        0     0
2      208927455  159     159    91    28       28        0     0
3      208927557  159     159    91    28       28        0     0


[4136 rows x 8 columns], 'NK2':            TimeUS    IVN    IVE   IVD    IPN   IPE    IPD IMX  IMY IMZ  IYAW  
0       207147350  -0.02   0.02  0.00  -0.02  0.01   0.20   0    0   0  1.94   
1       207187259  -0.02   0.02  0.00  -0.02  0.01   0.20   0    0   0  1.94   
2       207227559  -0.02   0.02  0.00  -0.02  0.01   0.14   0    0   0  1.77   
3       207308304   0.02   0.02  0.00  -0.01  0.01  -0.05   0    0   0  1.77   
4       207347766   0.02   0.02  0.00  -0.01  0.01  -0.05   0    0   0  0.82  

I first separated the column I want to do math with:

new_time = dfs['XYF']['TimeUS']

Then I have tried several things to do some math on it but I had no luck. First I just treated it like a list. so

new_time_F = new_time / 1000000

That didn't work, gave me a float error of:

TypeError: unsupported operand type(s) for /: 'str' and 'int'

so I did this:

new_time_F = float (new_time) / 1000000

This give me an error:

TypeError: cannot convert the series to <class 'float'>

I have no idea where to go from here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What if you do this (as was suggested earlier):

new_time = dfs['XYF']['TimeUS'].astype(float)
new_time_F = new_time / 1000000

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...