Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert dataframe to float

df["data"] = df["data"].astype(float)
Comment

object to int and float conversion pandas

In [39]:

df['2nd'] = df['2nd'].str.replace(',','').astype(int)
df['CTR'] = df['CTR'].str.replace('%','').astype(np.float64)
df.dtypes
Out[39]:
Date         object
WD            int64
Manpower    float64
2nd           int32
CTR         float64
2ndU        float64
T1            int64
T2            int64
T3            int64
T4           object
dtype: object
In [40]:

df.head()
Out[40]:
        Date  WD  Manpower   2nd   CTR  2ndU   T1    T2   T3     T4
0   2013/4/6   6       NaN  2645  5.27  0.29  407   533  454    368
1   2013/4/7   7       NaN  2118  5.89  0.31  257   659  583    369
2  2013/4/13   6       NaN  2470  5.38  0.29  354   531  473    383
3  2013/4/14   7       NaN  2033  6.77  0.37  396   748  681    458
4  2013/4/20   6       NaN  2690  5.38  0.29  361   528  541    381
Comment

PREVIOUS NEXT
Code Example
Python :: text to pandas 
Python :: python pop up box 
Python :: how to know where python is installed on windows 
Python :: python remove a key from a dictionary 
Python :: get all values of a dict python 
Python :: all combination of params 
Python :: python basename 
Python :: How to get the current user email from the account logged in? odoo 
Python :: numpy set_printoptions 
Python :: python delete key from dict 
Python :: sqlalchemy check if database exists 
Python :: message tags in django 
Python :: plt show 2 images 
Python :: python wikipedia api search 
Python :: how to compare current date to future date pythono 
Python :: python loop break on keypress 
Python :: how to import tkinter in python 
Python :: openpyxl add worksheet 
Python :: printing with format float to 2 decimal places python 
Python :: django timezone india 
Python :: The following code shows how to reset the index of the DataFrame and drop the old index completely: 
Python :: python print unicode character 
Python :: The `.create()` method does not support writable nested fields by default. Write an explicit `.create()` method for serializer `room_api.serializers.roomSerializer`, or set `read_only=True` on nested serializer fields. 
Python :: python list remove spaces 
Python :: how to add up a list in python 
Python :: train,test,dev python 
Python :: parse first characters from string python 
Python :: selenium webdriver 
Python :: column contains substring python 
Python :: random hex color python 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =