pandas.DataFrame.replace() got “OverflowError: Python int too large to convert to C long” [duplicate] The Next CEO of Stack OverflowOverflowError: Python int too large to convert to C longHandling HUGE numbers in numpy or pandasConvert hex string to int in PythonConvert two lists into a dictionary in PythonHow do I parse a string to a float or int in Python?Converting integer to string in Python?Best way to convert string to bytes in Python 3?Pythonic way to create a long multi-line stringlong hex string to integer in python“OverflowError: Python int too large to convert to C long” with astropy.tablePython- 'ValueError: invalid literal for int() with base 10' When Converting a List with Strings to IntegersPandas csv read: dtype int too large to convert to C long

Return the Closest Prime Number

Is "for causing autism in X" grammatical?

Is it possible to search for a directory/file combination?

How did people program for Consoles with multiple CPUs?

What flight has the highest ratio of time difference to flight time?

Indicator light circuit

Why does the UK parliament need a vote on the political declaration?

Unreliable Magic - Is it worth it?

If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Are there any unintended negative consequences to allowing PCs to gain multiple levels at once in a short milestone-XP game?

Skipping indices in a product

How do I go from 300 unfinished/half written blog posts, to published posts?

What is the purpose of the Evocation wizard's Potent Cantrip feature?

Is micro rebar a better way to reinforce concrete than rebar?

If a black hole is created from light, can this black hole then move at speed of light?

Won the lottery - how do I keep the money?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Novel about a guy who is possessed by the divine essence and the world ends?

What is "(CFMCC)" on an ILS approach chart?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Interfacing a button to MCU (and PC) with 50m long cable

Between two walls



pandas.DataFrame.replace() got “OverflowError: Python int too large to convert to C long” [duplicate]



The Next CEO of Stack OverflowOverflowError: Python int too large to convert to C longHandling HUGE numbers in numpy or pandasConvert hex string to int in PythonConvert two lists into a dictionary in PythonHow do I parse a string to a float or int in Python?Converting integer to string in Python?Best way to convert string to bytes in Python 3?Pythonic way to create a long multi-line stringlong hex string to integer in python“OverflowError: Python int too large to convert to C long” with astropy.tablePython- 'ValueError: invalid literal for int() with base 10' When Converting a List with Strings to IntegersPandas csv read: dtype int too large to convert to C long










1
















This question already has an answer here:



  • OverflowError: Python int too large to convert to C long

    3 answers



When I use pandas.DataFrame.replace(dict) to convert user_id string to integer, I receive:




"OverflowError: Python int too large to convert to C long".




sample code:



import pandas as pd
x = 'user_id':['100000715097692381911',
'100003840837471130074'],
'item_id': [1, 2]

dfx = pd.DataFrame(x)
dfx['user_id'].replace(

'100000715097692381911': 0,
'100003840837471130074': 1
, inplace=True)


I don't understand why this is duplicated. I think this is a problem of pandas taking str type as integers. I didn't load those big id numbers as integer but as string. Well, if I prepend an character to 'user_id' string, like 's100000715097692381911', it will not report OverflowError.










share|improve this question















marked as duplicate by jezrael dataframe
Users with the  dataframe badge can single-handedly close dataframe questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 8 at 14:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • @Aeossa I searched before asking, and it seems the link you post can't solve my problem. I think maybe pandas somehow take the user_id string as a large integer? But dfx.dtypes shows its type is object

    – Weihao Wang
    Mar 8 at 14:32
















1
















This question already has an answer here:



  • OverflowError: Python int too large to convert to C long

    3 answers



When I use pandas.DataFrame.replace(dict) to convert user_id string to integer, I receive:




"OverflowError: Python int too large to convert to C long".




sample code:



import pandas as pd
x = 'user_id':['100000715097692381911',
'100003840837471130074'],
'item_id': [1, 2]

dfx = pd.DataFrame(x)
dfx['user_id'].replace(

'100000715097692381911': 0,
'100003840837471130074': 1
, inplace=True)


I don't understand why this is duplicated. I think this is a problem of pandas taking str type as integers. I didn't load those big id numbers as integer but as string. Well, if I prepend an character to 'user_id' string, like 's100000715097692381911', it will not report OverflowError.










share|improve this question















marked as duplicate by jezrael dataframe
Users with the  dataframe badge can single-handedly close dataframe questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 8 at 14:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • @Aeossa I searched before asking, and it seems the link you post can't solve my problem. I think maybe pandas somehow take the user_id string as a large integer? But dfx.dtypes shows its type is object

    – Weihao Wang
    Mar 8 at 14:32














1












1








1









This question already has an answer here:



  • OverflowError: Python int too large to convert to C long

    3 answers



When I use pandas.DataFrame.replace(dict) to convert user_id string to integer, I receive:




"OverflowError: Python int too large to convert to C long".




sample code:



import pandas as pd
x = 'user_id':['100000715097692381911',
'100003840837471130074'],
'item_id': [1, 2]

dfx = pd.DataFrame(x)
dfx['user_id'].replace(

'100000715097692381911': 0,
'100003840837471130074': 1
, inplace=True)


I don't understand why this is duplicated. I think this is a problem of pandas taking str type as integers. I didn't load those big id numbers as integer but as string. Well, if I prepend an character to 'user_id' string, like 's100000715097692381911', it will not report OverflowError.










share|improve this question

















This question already has an answer here:



  • OverflowError: Python int too large to convert to C long

    3 answers



When I use pandas.DataFrame.replace(dict) to convert user_id string to integer, I receive:




"OverflowError: Python int too large to convert to C long".




sample code:



import pandas as pd
x = 'user_id':['100000715097692381911',
'100003840837471130074'],
'item_id': [1, 2]

dfx = pd.DataFrame(x)
dfx['user_id'].replace(

'100000715097692381911': 0,
'100003840837471130074': 1
, inplace=True)


I don't understand why this is duplicated. I think this is a problem of pandas taking str type as integers. I didn't load those big id numbers as integer but as string. Well, if I prepend an character to 'user_id' string, like 's100000715097692381911', it will not report OverflowError.





This question already has an answer here:



  • OverflowError: Python int too large to convert to C long

    3 answers







python python-3.x pandas dataframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 15:01







Weihao Wang

















asked Mar 8 at 14:23









Weihao WangWeihao Wang

112




112




marked as duplicate by jezrael dataframe
Users with the  dataframe badge can single-handedly close dataframe questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 8 at 14:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by jezrael dataframe
Users with the  dataframe badge can single-handedly close dataframe questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 8 at 14:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • @Aeossa I searched before asking, and it seems the link you post can't solve my problem. I think maybe pandas somehow take the user_id string as a large integer? But dfx.dtypes shows its type is object

    – Weihao Wang
    Mar 8 at 14:32


















  • @Aeossa I searched before asking, and it seems the link you post can't solve my problem. I think maybe pandas somehow take the user_id string as a large integer? But dfx.dtypes shows its type is object

    – Weihao Wang
    Mar 8 at 14:32

















@Aeossa I searched before asking, and it seems the link you post can't solve my problem. I think maybe pandas somehow take the user_id string as a large integer? But dfx.dtypes shows its type is object

– Weihao Wang
Mar 8 at 14:32






@Aeossa I searched before asking, and it seems the link you post can't solve my problem. I think maybe pandas somehow take the user_id string as a large integer? But dfx.dtypes shows its type is object

– Weihao Wang
Mar 8 at 14:32













1 Answer
1






active

oldest

votes


















1














In C, a long is 4 bytes and can only store values between -2,147,483,648 and 2,147,483,647.



To answer your other question, a string in C is stored as a char array, and so it's memory space is 1 byte for each char, plus the size of the terminating pointer. This means a python string in C won't cause an overflow, but a large integer will.



Source: https://www.tutorialspoint.com/cprogramming/c_data_types.htm






share|improve this answer























  • Thanks, but I didn't load those big numbers as integers. You can see that they are string type in my code.

    – Weihao Wang
    Mar 8 at 14:44











  • @WeihaoWang Loading the big numbers as ints might help you. Try letting the big numbers be ints, and change your df definition to dfx = pd.DataFrame(x, dtype=str) and then changing your replace to look for int keys instead

    – Luke Ning
    Mar 8 at 14:51












  • I tried your suggestion, it doesn't work. Thank you anyway. Could it be a bug of pandas?

    – Weihao Wang
    Mar 8 at 14:58











  • @WeihaoWang really? it worked for me. Are you still getting an overflow error?

    – Luke Ning
    Mar 8 at 15:02











  • uh.. it didn't report overflow, but the elements are not replaced with correct values.

    – Weihao Wang
    Mar 8 at 15:09

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In C, a long is 4 bytes and can only store values between -2,147,483,648 and 2,147,483,647.



To answer your other question, a string in C is stored as a char array, and so it's memory space is 1 byte for each char, plus the size of the terminating pointer. This means a python string in C won't cause an overflow, but a large integer will.



Source: https://www.tutorialspoint.com/cprogramming/c_data_types.htm






share|improve this answer























  • Thanks, but I didn't load those big numbers as integers. You can see that they are string type in my code.

    – Weihao Wang
    Mar 8 at 14:44











  • @WeihaoWang Loading the big numbers as ints might help you. Try letting the big numbers be ints, and change your df definition to dfx = pd.DataFrame(x, dtype=str) and then changing your replace to look for int keys instead

    – Luke Ning
    Mar 8 at 14:51












  • I tried your suggestion, it doesn't work. Thank you anyway. Could it be a bug of pandas?

    – Weihao Wang
    Mar 8 at 14:58











  • @WeihaoWang really? it worked for me. Are you still getting an overflow error?

    – Luke Ning
    Mar 8 at 15:02











  • uh.. it didn't report overflow, but the elements are not replaced with correct values.

    – Weihao Wang
    Mar 8 at 15:09















1














In C, a long is 4 bytes and can only store values between -2,147,483,648 and 2,147,483,647.



To answer your other question, a string in C is stored as a char array, and so it's memory space is 1 byte for each char, plus the size of the terminating pointer. This means a python string in C won't cause an overflow, but a large integer will.



Source: https://www.tutorialspoint.com/cprogramming/c_data_types.htm






share|improve this answer























  • Thanks, but I didn't load those big numbers as integers. You can see that they are string type in my code.

    – Weihao Wang
    Mar 8 at 14:44











  • @WeihaoWang Loading the big numbers as ints might help you. Try letting the big numbers be ints, and change your df definition to dfx = pd.DataFrame(x, dtype=str) and then changing your replace to look for int keys instead

    – Luke Ning
    Mar 8 at 14:51












  • I tried your suggestion, it doesn't work. Thank you anyway. Could it be a bug of pandas?

    – Weihao Wang
    Mar 8 at 14:58











  • @WeihaoWang really? it worked for me. Are you still getting an overflow error?

    – Luke Ning
    Mar 8 at 15:02











  • uh.. it didn't report overflow, but the elements are not replaced with correct values.

    – Weihao Wang
    Mar 8 at 15:09













1












1








1







In C, a long is 4 bytes and can only store values between -2,147,483,648 and 2,147,483,647.



To answer your other question, a string in C is stored as a char array, and so it's memory space is 1 byte for each char, plus the size of the terminating pointer. This means a python string in C won't cause an overflow, but a large integer will.



Source: https://www.tutorialspoint.com/cprogramming/c_data_types.htm






share|improve this answer













In C, a long is 4 bytes and can only store values between -2,147,483,648 and 2,147,483,647.



To answer your other question, a string in C is stored as a char array, and so it's memory space is 1 byte for each char, plus the size of the terminating pointer. This means a python string in C won't cause an overflow, but a large integer will.



Source: https://www.tutorialspoint.com/cprogramming/c_data_types.htm







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 14:35









Luke NingLuke Ning

926




926












  • Thanks, but I didn't load those big numbers as integers. You can see that they are string type in my code.

    – Weihao Wang
    Mar 8 at 14:44











  • @WeihaoWang Loading the big numbers as ints might help you. Try letting the big numbers be ints, and change your df definition to dfx = pd.DataFrame(x, dtype=str) and then changing your replace to look for int keys instead

    – Luke Ning
    Mar 8 at 14:51












  • I tried your suggestion, it doesn't work. Thank you anyway. Could it be a bug of pandas?

    – Weihao Wang
    Mar 8 at 14:58











  • @WeihaoWang really? it worked for me. Are you still getting an overflow error?

    – Luke Ning
    Mar 8 at 15:02











  • uh.. it didn't report overflow, but the elements are not replaced with correct values.

    – Weihao Wang
    Mar 8 at 15:09

















  • Thanks, but I didn't load those big numbers as integers. You can see that they are string type in my code.

    – Weihao Wang
    Mar 8 at 14:44











  • @WeihaoWang Loading the big numbers as ints might help you. Try letting the big numbers be ints, and change your df definition to dfx = pd.DataFrame(x, dtype=str) and then changing your replace to look for int keys instead

    – Luke Ning
    Mar 8 at 14:51












  • I tried your suggestion, it doesn't work. Thank you anyway. Could it be a bug of pandas?

    – Weihao Wang
    Mar 8 at 14:58











  • @WeihaoWang really? it worked for me. Are you still getting an overflow error?

    – Luke Ning
    Mar 8 at 15:02











  • uh.. it didn't report overflow, but the elements are not replaced with correct values.

    – Weihao Wang
    Mar 8 at 15:09
















Thanks, but I didn't load those big numbers as integers. You can see that they are string type in my code.

– Weihao Wang
Mar 8 at 14:44





Thanks, but I didn't load those big numbers as integers. You can see that they are string type in my code.

– Weihao Wang
Mar 8 at 14:44













@WeihaoWang Loading the big numbers as ints might help you. Try letting the big numbers be ints, and change your df definition to dfx = pd.DataFrame(x, dtype=str) and then changing your replace to look for int keys instead

– Luke Ning
Mar 8 at 14:51






@WeihaoWang Loading the big numbers as ints might help you. Try letting the big numbers be ints, and change your df definition to dfx = pd.DataFrame(x, dtype=str) and then changing your replace to look for int keys instead

– Luke Ning
Mar 8 at 14:51














I tried your suggestion, it doesn't work. Thank you anyway. Could it be a bug of pandas?

– Weihao Wang
Mar 8 at 14:58





I tried your suggestion, it doesn't work. Thank you anyway. Could it be a bug of pandas?

– Weihao Wang
Mar 8 at 14:58













@WeihaoWang really? it worked for me. Are you still getting an overflow error?

– Luke Ning
Mar 8 at 15:02





@WeihaoWang really? it worked for me. Are you still getting an overflow error?

– Luke Ning
Mar 8 at 15:02













uh.. it didn't report overflow, but the elements are not replaced with correct values.

– Weihao Wang
Mar 8 at 15:09





uh.. it didn't report overflow, but the elements are not replaced with correct values.

– Weihao Wang
Mar 8 at 15:09





Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived