• Register
0 votes

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:


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?

6 5 3
7,540 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)
9 7 4
38,600 points

Related questions

0 votes
1 answer 11 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 32 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 835 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
2 votes
2 answers 1.9K 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
1 vote
1 answer 979 views
Problem : I am facing bellow strange error undefinedmetricwarning: precision is ill-defined and being set to 0.0 due to no predicted samples.
asked Nov 8, 2019 peterlaw 6.9k points
0 votes
1 answer 14 views
Problem: So I know that I should avoid using globals in the first place because of confusion like this, but if I were to use them, could I use them correctly? (I am trying to call a global copy of a variable created in a separate function.) x = somevalue def func_A ... me i am in a search of answer actually i donot have idea that how to define vaiable globally and how i can edit its value anyone ?
asked Nov 10, 2020 Han Li 710 points
0 votes
1 answer 105 views
Problem: I am trying to create a 16-bit image like so: import skimage import random from random import randint xrow=raw_input("Enter the number of rows to be present in image.=>") row=int(xrow) ycolumn=raw_input("Enter the number of columns to be present in image.=>") column=int ... ,column): a=randint(0,65535) A[x,y]=a imshow(A) But I get the error TypeError: Image data can not convert to float.p
asked Feb 19 Mashhoodch 13k points
0 votes
1 answer 74 views
Problem: org.json.jsonexception: value <br of type java.lang.string cannot be converted to jsonobject
asked Feb 18 Lucky Guy 1.5k points