Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

I need to change the type of few columns in a pandas dataframe. Can't do so using iloc

I guess it is a bug in 1.0.5. I tested on my 1.0.5. I have the same issue as yours. The .loc also has the same issue, so I guess pandas devs break something in iloc/loc. You need to update to latest pandas or use a workaround. If you need a workaround, using assignment as follows

df1[df1.columns[0:27]] = df1.iloc[:, 0:27].astype('int')

I tested it. Above way overcomes this bug. It will turn first 27 columns to dtype int32

Tags:

Python

Pandas

Types

Casting

Dataframe

Related

Xcode 12 - No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=arm64e armv7s arm64 arm7) Why can't I find any law violations for the NotQuiteCofree not-quite-comonad? Testing streaming service (like selenium) Why are some properties repeated when TRttiContext.GetType is called on a VCL Control? Double cast to unsigned int on Win32 is truncating to 2,147,483,648 KeyError on If-Condition in dictionary Python How to delete all instances of a repeated number in a list? Launch Screen not working on iOS 14 with Xcode 12 Carthage build failed Xcode 12 12A7209 building How to convert a dataframe from long to wide, with values grouped by year in the index? Why is the function return in C a statement? The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, in Flutter How can I change the minimum IOS Deploying Target

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy