• Register
0 votes
4k 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?

6 5 3
7,540 points

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 459 views
459 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 jwilliam 3.9k points
1 vote
1 answer 232 views
232 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
2 votes
2 answers 239 views
239 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 samhaz 5k points
1 vote
1 answer 148 views
148 views
Problem : I am very new to Python. While trying to execute my code I am facing below warning C:\Python27\lib\site-packages\pandas\core\indexing.py:411: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer ... '] = mydf.review_text.map(lambda x: tokenizer.tokenize(x)) print mydf[:3] I am looking for expert help to fix above error.
asked Apr 27 stewart 4k points