Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

geopandas change columns dtype

# Individual  
df['a'] = df_test['a'].astype('float64')
df['b'] = df_test['b'].astype('int64')
# Batch
dtype_d = {"a": "float64", "b": "int64"} # dtype dictio
df = df.astype(dtype_d)
Comment

geopandas replace column name

# Geopandas use the same rename function as Pandas.

import geopandas as gpd

gdf = gpd.GeoDataFrame({'x':['John', 'Doe', 'Paul'], 
        'y':[22, 31, 15],
        'z':[[-45.23332,34.23556], [-45.32565,34.49347], [-45.27648,34.45284]]
        })
columns_Name = {'x': 'name', 'y': 'age', 'z': 'location'}
gdf = gdf.rename(columns = columns_Name)
gdf
   name  age               location
0  John   22  [-45.23332, 34.23556]
1   Doe   31  [-45.32565, 34.49347]
2  Paul   15  [-45.27648, 34.45284]

# When you want the change to be implicitly saved
columns_Name = {'x': 'name', 'y': 'age', 'z': 'location'}
gdf.rename(columns = columns_Name, inplace=True)

Comment

PREVIOUS NEXT
Code Example
Python :: datetime64 ns to date python 
Python :: reactstrap example 
Python :: python selenium click on agree button 
Python :: sum range 
Python :: python get element by index 
Python :: items of list 
Python :: tkinter textboxe position 
Python :: how to pre populate field flask wtforms 
Python :: python lock file 
Python :: networkx node attribute from a dataframe 
Python :: Sum of all substrings of a number 
Python :: make virtual environment python 
Python :: pandas merge sort columns 
Python :: python running mean pandas 
Python :: Set path for another directory 
Python :: loading a webpage with aiohttp 
Python :: python cron job virtualenv 
Python :: Maximize Difference codechef solution 
Python :: python types of loops 
Python :: run multiprocesses on flask 
Python :: how to define a functio in python 
Python :: duplicate a list with for loop in python 
Python :: windows python absolute path 
Python :: save jupyter notebook session 
Python :: calendar library in python 
Python :: <pandas.core.groupby.generic.dataframegroupby object 
Python :: Renaming and replacing the column variable name 
Python :: django MESSAGE_TAGS 
Python :: get midnight of current day python 
Python :: how to while true python 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =