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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page