Spatial Digger
Spatial Digger

Reputation: 1993

Adding a value to geopandas empty geodataframe n times

I'm trying to add a fixed value n times to an empty (geo)dataframe, I thought the below was the way to do it, but I can't seem to get it to work, where am I going wrong?

features = gpd.GeoDataFrame()
n=100
value = 'a'
gdf['new_column-name'] = value * n

Upvotes: 1

Views: 913

Answers (2)

Subbu VidyaSekar
Subbu VidyaSekar

Reputation: 2615

Use this format:

gdf = pd.DataFrame(value, index=range(n),columns=['new_col_name'])

your way of creating dataframe:

gdf = pd.DataFrame()
gdf['new_column-name'] = [value] * n
gdf

Upvotes: 1

r-beginners
r-beginners

Reputation: 35205

This is the easiest way. Thanks for giving me a chance to answer.

gdf['new_column-name'] = [value] * n

Upvotes: 1

Related Questions