That way of merging is creating a Pandas DataFrame. Try this:

import geopandas as gpd

df = gpd.read_file(r"/home/bera/Drives/data1/data/LMV/LMV-data_2021-10/ok_riks_Sweref_99_TM_shape/oversikt/riks/ak_riks.shp")

gdf1 = df.head(10)
gdf2 = df.tail(10)

print(type(gdf1.merge(gdf2, on="LANSKOD", how="outer"))) #This is creating a pandas df
#pandas.core.frame.DataFrame

merged = gpd.pd.merge(gdf1, gdf2, on="LANSKOD", how="outer")
print(type(merged))
#<class 'geopandas.geodataframe.GeoDataFrame'> #Now it is a geopandas df

merged["geometry"] = merged["geometry_x"].combine_first(merged["geometry_y"]) #Create a complete geometry column
merged = merged.drop(columns=["geometry_x", "geometry_y"])
merged.to_file(r"/home/bera/Desktop/GIStest/testmerge.shp")
Answer from Bera on Stack Exchange
🌐
Esri Community
community.esri.com › t5 › arcgis-notebooks-questions › spatial-data-frame-failing-to-output-as-feature › td-p › 1150249
Spatial data frame failing to output as feature cl... - Esri Community
April 28, 2022 - sdf.spatial.to_featureLayer('sdf_to_featureLayer') #this is the resulting error --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /tmp/ipykernel_393/3728460398.py in <module> ----> 1 sdf.spatial.to_featureLayer('spf_to_featureLayer') AttributeError: 'GeoAccessor' object has no attribute 'to_featureLayer'
🌐
GitHub
github.com › Esri › arcgis-python-api › issues › 1193
df.spatial.to_table() returns AttributeError when converting dataframe to table · Issue #1193 · Esri/arcgis-python-api
March 1, 2022 - All of the columns within the dataframe are objects. To Reproduce Steps to reproduce the behavior: df = pd.read_csv('sample.csv') df.spatial.to_table() error: AttributeError Traceback (most recent call last) In [15]: Line 2: df.spatial.to_table(location=unearthName_clean) File C:\Users\eric.samson\AppData\Local\ESRI\conda\envs\EricENV_20210104\Lib\site-packages\arcgis\features\geo\_accessor.py, in to_table: Line 2413: to_table, **{"geo": self, "location": location, "overwrite": overwrite} File C:\Users\eric.samson\AppData\Local\ESRI\conda\envs\EricENV_20210104\Lib\site-packages\arcgis\features
Author   EricSamsonCarto
🌐
Stack Exchange
gis.stackexchange.com › questions › 317022 › generating-queried-csv-from-shapefile-using-arcgis-api-for-python
pandas - Generating Queried CSV from shapefile using ArcGIS API for Python? - Geographic Information Systems Stack Exchange
from arcgis.gis import GIS from arcgis.features import FeatureLayer from arcgis.features import manage_data from datetime import date, time import pandas as pd from arcgis.features import SpatialDataFrame gis = GIS("https://------", username="---------", password="---------") item_id='---------' get = gis.content.get(item_id) feeder = get.layers[0] sdf = pd.DataFrame.spatial.from_layer(feeder) df = feeder.query(where="feeder_status = 'Closed'").sdf df.head() This throws the following error: AttributeError: type object 'DataFrame' has no attribute 'spatial'
🌐
Stack Overflow
stackoverflow.com › questions › 48318417 › how-can-i-pass-the-attributeerror-dataframe-object-has-no-attribute-flatten
spatial - How can I pass the AttributeError: 'DataFrame' object has no attribute 'flatten in Python? - Stack Overflow
January 18, 2018 - import libpysal #f = libpysal.io.open(libpysal.examples.get_path("usjoin.csv")) f = pd.read_csv("Last37API.csv") pci = np.array([f.by_col[str(y)] for y in range(1,1096)]) print(pci.shape) I got this error AttributeError: 'DataFrame' object has no attribute 'by_col'
Find elsewhere
🌐
GitHub
github.com › rpy2 › rpy2 › issues › 680
AttributeError: type object 'DataFrame' has no attribute 'from_items' · Issue #680 · rpy2/rpy2
April 9, 2020 - Need to change this to .from_dict for pandas ≥ 1.0 ~/anaconda3/envs/soothsayer_env/lib/python3.6/site-packages/rpy2/robjects/pandas2ri.py in ri2py_dataframe(obj) 189 def ri2py_dataframe(obj): 190 i...
Author   jolespin
🌐
Edureka Community
edureka.co › home › community › categories › python › attributeerror dataframe object has no...
AttributeError DataFrame object has no attribute is impossible | Edureka Community
March 10, 2020 - from collections import Counter import re import numpy as np import pandas as pd from nltk. ... 'DataFrame' object has no attribute 'is_impossible'
🌐
Esri Community
community.esri.com › t5 › arcgis-api-for-python-questions › how-to-plot-a-specific-geometry-column-of-spatial › td-p › 1235165
How to plot a specific geometry column of Spatial enabled DataFrames?
December 5, 2022 - Following the introduction, a buffer geometry is added to the dataframe. The map widget of my notebook is however, only showing the points. How can I visualize the buffer geometries? Is there a way to specify what geometry column should be used for the visualization? # generates map widget visulizing the points, though info widgets places two objects there, when I click on a point point_df.spatial.plot() # AttributeError: 'Series' object has no attribute 'spatial' point_df.Buffer_2.spatial.plot() # Since plot generates a MapView, the object is not subscriptable point_df.spatial.plot()['Buffer_2'] # or has no attribute 'Buffer_2' point_df.spatial.plot().Buffer_2
🌐
GitHub
github.com › keplergl › kepler.gl › issues › 1758
[Bug][Jupyter Widget] add_data with GeoDataFrame only works if the geometry column is called "geometry" · Issue #1758 · keplergl/kepler.gl
March 28, 2022 - Error Message: AttributeError: 'DataFrame' object has no attribute 'geometry' with a stack pointing to the file keplergl.py line 44: df[name] = df.geometry.apply(lambda x: shapely.wkt.dumps(x))
Author   remi-sap
🌐
Quora
quora.com › How-do-you-fix-pandas-that-have-no-attribute-dataframe
How to fix pandas that have no attribute dataframe - Quora
Now, if you confuse a list object with an array and try to access the attribute shape, it throws an error stating object has no attribute shape. Hope this helps. ... Why is Pandas DataFrame merge casting float values to integers (Python, Pandas, DataFrame, development)?
Top answer
1 of 5
2

"sklearn.datasets" is a scikit package, where it contains a method load_iris().

load_iris(), by default return an object which holds data, target and other members in it. In order to get actual values you have to read the data and target content itself.

Whereas 'iris.csv', holds feature and target together.

FYI: If you set return_X_y as True in load_iris(), then you will directly get features and target.

from sklearn import datasets
data,target = datasets.load_iris(return_X_y=True)
2 of 5
1

The Iris Dataset from Sklearn is in Sklearn's Bunch format:

print(type(iris))
print(iris.keys())

output:

<class 'sklearn.utils.Bunch'>
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename'])

So, that's why you can access it as:

x=iris.data
y=iris.target

But when you read the CSV file as DataFrame as mentioned by you:

iris = pd.read_csv('iris.csv',header=None).iloc[:,2:4]
iris.head()

output is:

    2   3
0   petal_length    petal_width
1   1.4 0.2
2   1.4 0.2
3   1.3 0.2
4   1.5 0.2

Here the column names are '1' and '2'.

First of all you should read the CSV file as:

df = pd.read_csv('iris.csv')

you should not include header=None as your csv file includes the column names i.e. the headers.

So, now what you can do is something like this:

X = df.iloc[:, [2, 3]] # Will give you columns 2 and 3 i.e 'petal_length' and 'petal_width'
y = df.iloc[:, 4] # Label column i.e 'species'

or if you want to use the column names then:

X = df[['petal_length', 'petal_width']]
y = df.iloc['species']

Also, if you want to convert labels from string to numerical format use sklearn LabelEncoder

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
y = le.fit_transform(y)
🌐
ArcGIS
developers.arcgis.com › python › latest › guide › spatially-enabled-dataframe-advanced-topics
Spatially Enabled DataFrames - Advanced Topics | ArcGIS API for Python | Esri Developer
We can see that the SHAPE column is of type geometry. This means that compared to the legacy SpatialDataFrame class, geometry columns are now unique instead of being just of type object. We can get information about each axis label (aka, index) with the axes property on the spatial dataframe.
🌐
Databricks Community
community.databricks.com › t5 › data-engineering › attributeerror-dataframe-object-has-no-attribute › td-p › 61132
AttributeError: 'DataFrame' object has no attribut... - Databricks Community - 61132
February 19, 2024 - Hello, I have some trouble deduplicating rows on the "id" column, with the method "dropDuplicatesWithinWatermark" in a pipeline. When I run this pipeline, I get the error message: "AttributeError: 'DataFrame' object has no attribute 'dropDuplicatesWithinWatermark'" Here is part of the code: @dl...