pandas.dataframe doesn't have a built-in reshape method, but you can use .values to access the underlying numpy array object and call reshape on it:

start = 0
for i in range(0, len(df.index)):
    if (i + 1)%10 == 0:
        result = df.iloc[start:i+1].values.reshape(2,5)
        start = i + 1
        print result

#[[ 52.1  32.2  44.6  99.1  12.3]
# [ 43.2  79.4  45.5  56.3  15.4]]
#[[ 35.7  23.7  66.7  33.8  12.9]
# [ 34.8  21.6  43.7  44.2  55.8]]
Answer from akuiper on Stack Overflow
🌐
GitHub
github.com › arturomoncadatorres › deepsurvk › issues › 81
'DataFrame' object has no attribute 'reshape' error in examples/01_using_deepsurvk.py · Issue #81 · arturomoncadatorres/deepsurvk
March 11, 2021 - AttributeError Traceback (most recent call last) <ipython-input-21-04b713b91b55> in <module> 4 # X_test = X_scaler.transform(X_test) 5 ----> 6 Y_scaler = StandardScaler().fit(Y_train.reshape(-1, 1)) 7 Y_train = Y_scaler.transform(Y_train) 8 Y_test = Y_scaler.transform(Y_test) C:\ProgramData\Anaconda3\envs\iknl-internship\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 5460 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5461 return self[name] -> 5462 return object.__getattribute__(self, name) 5463 5464 def __setattr__(self, name: str, value) -> None: AttributeError: 'DataFrame' object has no attribute 'reshape' DeepSurvK version: 0.2.0 ·
Author   FoppeCrezee
Discussions

AttributeError: 'DataFrame' object has no attribute 'reshape'
Hi, In this code I get the error. Where the X_pool shape is (1024, 8). query_idx, query_instances = learner.query(X_pool, n_instances=5) Please let me know what is wrong here. I used the Ranked bat... More on github.com
🌐 github.com
2
September 2, 2021
BUG: Series has no attribute "reshape" after adding a new category in df
I have checked that this issue has not already been reported. I have confirmed this bug exists on the latest version of pandas. (optional) I have confirmed this bug exists on the master branch of p... More on github.com
🌐 github.com
8
August 14, 2020
Seeing AttributeError: 'Dataset' object has no attribute 'reshape' when using "dataset.get_nearest_examples"
Hello, I am trying to use Faiss indexing for an image similarity application. However, I am seeing an Attribute Error. Here’s the code that I am trying # Loading dataset dataset = load_dataset("imagefolder", data_dir="/… More on discuss.huggingface.co
🌐 discuss.huggingface.co
0
0
June 25, 2023
python 3.x - DataFrame has no Reshape Attribute - Stack Overflow
I'm trying to plot to scatter the graph on the following conditions. But, it failed to give a graph. First, it gave me the error message, X and Y size are not equal. Then, when I tried to reshape the More on stackoverflow.com
🌐 stackoverflow.com
🌐
Coder Legion
coderlegion.com › 367 › resolved-attributeerror-dataframe-object-has-no-attribute-reshape
Resolved: Attributeerror: 'dataframe' object has no attribute 'reshape' - Coder Legion
Encountering the `AttributeError 'DataFrame' object has no attribute 'reshape'` is common when using Pandas in Python. It happens due to the absence of the reshape attribute within the DataFrame class, especially during reshaping operations. ...
🌐
GitHub
github.com › modAL-python › modAL › issues › 139
AttributeError: 'DataFrame' object has no attribute 'reshape' · Issue #139 · modAL-python/modAL
September 2, 2021 - AttributeError: 'DataFrame' object has no attribute 'reshape'#139 · Copy link · ghezalahmad · opened · on Sep 2, 2021 · Issue body actions · Hi, In this code I get the error. Where the X_pool shape is (1024, 8). query_idx, query_instances = learner.query(X_pool, n_instances=5) Please let me know what is wrong here.
Author   ghezalahmad
🌐
GitHub
github.com › pandas-dev › pandas › issues › 35731
BUG: Series has no attribute "reshape" after adding a new category in df · Issue #35731 · pandas-dev/pandas
August 14, 2020 - -> 2747 values = values.reshape(tuple((1,) + shape)) # type: ignore 2748 return values 2749 ~/.pyenv/versions/3.7.0/envs/fair_ml/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name) 5128 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5129 return self[name] -> 5130 return object.__getattribute__(self, name) 5131 5132 def __setattr__(self, name: str, value) -> None: AttributeError: 'Series' object has no attribute 'reshape'
Author   chen-bowen
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: ‘dataframe’ object has no attribute ‘reshape’
[Solved] attributeerror: 'dataframe' object has no attribute 'reshape'
April 19, 2023 - The AttributeError: ‘DataFrame’ object has no attribute ‘reshape’ error occurs because the DataFrame object in pandas does not have a reshape attribute.
🌐
Hugging Face
discuss.huggingface.co › 🤗datasets
Seeing AttributeError: 'Dataset' object has no attribute 'reshape' when using "dataset.get_nearest_examples" - 🤗Datasets - Hugging Face Forums
June 25, 2023 - Hello, I am trying to use Faiss indexing for an image similarity application. However, I am seeing an Attribute Error. Here’s the code that I am trying # Loading dataset dataset = load_dataset("imagefolder", data_dir="/…
🌐
Coder Legion
coderlegion.com › 367 › attributeerror-dataframe-object-has-no-attribute-reshape
Attributeerror: 'dataframe' object has no attribute 'reshape' - Coder Legion
Encountering the `AttributeError 'DataFrame' object has no attribute 'reshape'` is common when using Pandas in Python. It happens due to the absence of the reshape attribute within the DataFrame class, especially during reshaping operations. ...
Find elsewhere
🌐
YouTube
youtube.com › the debug zone
"DataFrame" object has no attribute 'reshape' - YouTube
python: "DataFrame" object has no attribute &#233 Thanks for taking the time to learn more. In this video I'll go through your question, provide va...
Published   June 5, 2023
Views   43
🌐
Data Science Learner
datasciencelearner.com › home › dataframe’ object has no attribute ‘reshape’ ( solved )
dataframe' object has no attribute 'reshape' ( Solved )
September 12, 2023 - Now you will not get the AttributeError when you will run the below lines of code. import numpy as np import pandas as pd np.random.seed(0) df = pd.DataFrame({'col1': list('pqrstuvw'), 'col2': np.random.choice(10, 8)}) df["col2"].values.reshape((-1,4)) ... The reshape() method allows you to change the dimension of the array. If you are getting the object has no attribute ‘reshape’ error then the above method will solve this error.
🌐
Stack Overflow
stackoverflow.com › questions › 58584468 › dataframe-has-no-reshape-attribute
python 3.x - DataFrame has no Reshape Attribute - Stack Overflow
The first error that you encounter meant that either the dimension of X_train.shape and y_train.shape are not consistent or the number of element of len(X_train) != len(y_train) or (X_train.shape[0] != (y_train.shape[0]). Besides, if your code is exactly what you posted, I don't see any relevance between df.reshape((df.shape[0], df.shape[1], 1)) and plt.scatter(X_train, y_train, color = 'red'). You need a trick to reshape pandas dataframe.
🌐
HatchJS
hatchjs.com › home › dataframe object has no attribute reshape: how to fix this error
DataFrame Object Has No Attribute Reshape: How to Fix This Error
January 5, 2024 - The DataFrame may not be in a valid state to be reshaped. To fix this error, you need to make sure that the DataFrame is a valid DataFrame object and that the `reshape()` method is defined.
🌐
Python Forum
python-forum.io › thread-13879.html
'list' object has no attribute 'reshape'
November 4, 2018 - Hi All, I've just joined this forum, also new to Python, with background in other languages. I've been trying a small piece of code below using jupyter ipython in notebooks.azure.com, the error is coming from the last call for np.reshape function w...
Top answer
1 of 1
1

I just tested your code* with pandas=0.24.1 and geopandas=0.4.0, and it ran without error.

For what it's worth, the geopandas documentation offers example code for Creating a GeoDataFrame from a DataFrame with coordinates, and it is not necessary to use iterrows on the DataFrame to build the geometries point by point, nor is it necessary to add the geometry column to the DataFrame first. Arguably, this should be avoided, so that you can distinguish between DataFrame that don't have geometries and GeoDataFrames that do.

The example code from the documentation. The code is slightly modified to follow your conventions:

import pandas as pd
import geopandas as gpd

city_dict = {'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
     'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
     'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],
     'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]}
df = pd.DataFrame(city_dict)
crs_dict = {'init': 'epsg:4326'}

gdf = gpd.GeoDataFrame(df, crs=crs_dict, 
    geometry=gpd.points_from_xy(df.Longitude, df.Latitude)
    )

If you are using geopandas<0.5.0, points_from_xy won't be available to you, in which case you can use a list compehension with the shapely Point constructor:

from shapely.geometry import Point

gdf = gpd.GeoDataFrame(df, crs=crs_dict, 
    geometry=[Point(x, y) for x, y in zip(df.Longitude, df.Latitude)]
    )

* I didn't test your exact code because you didn't supply city data. I used the example dict given above from the geopandas documentation.

🌐
Reddit
reddit.com › r/learnpython › how to fix: pandas profiling (v 2.8) error: 'series' object has no attribute 'reshape'
r/learnpython on Reddit: How to fix: Pandas Profiling (v 2.8) Error: 'Series' object has no attribute 'reshape'
September 3, 2020 - -> 2744 values = values.reshape(tuple((1,) + shape)) # type: ignore 2745 return values 2746 ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 5128 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5129 return self[name] -> 5130 return object.__getattribute__(self, name) 5131 5132 def __setattr__(self, name: str, value) -> None: AttributeError: 'Series' object has no attribute 'reshape' ... Nobody's responded to this post yet. Add your thoughts and get the conversation going. Why am I suddenly getting "AttributeError: 'Index' ob
🌐
Codecademy Forums
discuss.codecademy.com › data science
AttributeError: 'DataFrame' object has no attribute 'fit' - Data Science - Codecademy Forums
May 6, 2024 - I’m working on the final project for Machine Learning Engineering. I’m using jupyter notebook to fit the data. When I try to fit the data, I keep getting an error message saying: " AttributeError: ‘DataFrame’ object h…
🌐
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...