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 change 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

geopandas change dtype of a columns

gdf_test['column_name'] = gdf_test['column_name'].astype('int64')
Comment

PREVIOUS NEXT
Code Example
Python :: how to redirect to previous page in django 
Python :: zero crossing rate python 
Python :: how to logout in django 
Python :: create an empty list of lists in python 
Python :: os.mkdir exceptions 
Python :: python edit global variable in function 
Python :: python num2words installation 
Python :: python sort array of dictionary by value 
Python :: how to run python module every 10 sec 
Python :: python list of dictionary unique 
Python :: how to get confusion matrix in python 
Python :: python if not null or empty 
Python :: histogram image processing python 
Python :: How to efficiently calculate the nth Catalan number, in Python? 
Python :: execute terminal command from python 
Python :: slug url 
Python :: python zip folder 
Python :: how to count null values in pandas and return as percentage 
Python :: numpy randint 
Python :: try except json decode error 
Python :: if main python 
Python :: Python program to print even numbers in a list 
Python :: findout not common values between two data frames 
Python :: Command errored out with exit status 1: 
Python :: remove tab space from string in python 
Python :: display prime numbers between two intervals in python 
Python :: python cv2 imwrite 
Python :: how to convert adjacency list to adjacency matrix 
Python :: write lines python with line breaks 
Python :: python package for misspelled words 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =