• Register
0 votes
7.9k views

Problem :

I am using Pandas 0.20.3 in my python 3.X. I for the first time and want to add one column in a pandas data frame from the other pandas data frame. My both the data frame contains 51 rows. So I tried following code:

class_df['phone']=group['phone'].values

But I got following error message:

ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series

My class_df.dtypes gives me :

Group_ID      object

YEAR           object

Terget           object

phone          object

age              object

Cost            object

RAM           object

Display       object

Storage      object

and when I type(group['phone']) it returns the pandas.core.series.Series

Can anyone suggest me what changes I need to do to remove above error?

7.5k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I have lots of industry experience in writing complex Python code.

I have gone through your post and understood your problem.

So to begin with you must follow below approach to resolve your issue:

I did lot of research and ultimately found that this error comes when you return an empty data frame. The best approach which ultimately worked for me was to check if the data frame is empty just before using apply() as follows:

if len(df) !=  0:
    df['indicator'] = df.apply(assign_indicator, axis=1)
38.6k points

Related questions

0 votes
1 answer 75 views
75 views
Problem : Can anyone suggest me what changes I need to do to remove above error: Cannot set a frame with no defined index and a value that cannot be converted to a series.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 82 views
82 views
Problem: I have a dynamic DataFrame that works fine, but when there is no data to add to the DataFrame, I get an error. And so I need a solution to create an empty DataFrame with only column names. Until then, I have something like this: df = pd.DataFrame(columns=COLUMN_NAMES) # Note ... "dataframe"> <tbody> <tr> <td>Index([], dtype='object')</td> <td>Empty DataFrame</td> </tr> </tbody> </table>
asked Dec 23, 2020 sasha 16.2k points
0 votes
1 answer 10 views
10 views
Problem: Does anyone know the solution : Only integer arrays with one element can be converted to an index?
asked Jun 20 Aurelia Maja 78.4k points
0 votes
1 answer 11 views
11 views
Problem: Is there anyone who knows the answer :Typeerror: only integer arrays with one element can be converted to an index?
asked Jun 15 Nahil 128k points
0 votes
1 answer 1k views
1k views
Problem : I am having below error in a title, and I don't know what's wrong. It was working when I used np.hstack instead of the np.append, but I want to make this faster, so using append. time_list the list of floats heights is the 1d np.array of ... <module> axe_x.append(time_list[np.arange(j+n,j+(time_interval-n))]) TypeError: only integer arrays with one element can be converted to an index
asked Jan 24, 2020 jwilliam 3.9k points
0 votes
1 answer 60 views
60 views
Problem: Try to discover this >Integer scalar arrays can be converted to a scalar index
asked May 11 Sawyer Parviz 168k points
0 votes
1 answer 61 views
61 views
Problem: I want to write a function that randomly picks elements from a training set, based on the bin probabilities provided. I divide the set indices to 11 bins, then create custom probabilities for them. bin_probs = [0.5, 0.3, 0.15, 0.04, 0.0025, 0.0025, 0.001, 0.001, ... It is 1-D, it is integer, and it is scalar. What am I missing? Note : I tried to pass indices with astype(int). Same error.
asked May 2 anika11 32.2k points
0 votes
0 answers 19 views
19 views
Problem: I have numpy data x = [[1. 2.2 3.4] [3. 4. 5. ]] and y = [[2.6660993 3.6791213 3.7325573]] Just want to concatenate these, result should be this. [[1. 2.2 3.4] [3. 4. 5. ] [2.6660993 3.6791213 3.7325573] ] However, np.concatenate(x,y) shows the error. only integer scalar arrays can be converted to a scalar index
asked May 1 Yeamin 23.5k points
2 votes
2 answers 2.5k views
2.5k views
Problem: I wrote the following code in python using numpy. But it gives me some error message. The code I wrote is: import numpy as np arrayone = np.array(['Human', 'Birds', 'Groots', 'Oats']) arraytwo = np.array(['Beach', 'Toast']) arraythree ... concatenate TypeError: only integer scalar arrays can be converted to a scalar index Can anyone sort out this error and solve this. Thanks in advance.
asked May 6, 2020 samhaz 5k points