It works
import textstat
text = (
"Playing games has always been thought to be important to ")
textstat.flesch_reading_ease(text)
BUT When I call dataframe's columns df['Contents']
df['Read']= textstat.flesch_reading_ease(df['Contents'])
I am getting the error:
TypeError Traceback (most recent call last)
<ipython-input-50-b897dfd2f80f> in <module>
----> 1 df['Read']= textstat.flesch_reading_ease(df.Contents)
TypeError: unhashable type: 'Series'
I deleted null data but it still doesn't work. The result was same.
TypeError: unhashable type: 'Series'
After using groupby function I want to convert that to a dataframe object but it shows error
My Code
dfgrp1 = df['Service 1'].groupby(['Service Type'])
dfgrp1 = dfgrp1.to_frame()
Output
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [18], in <cell line: 2>()
1 dfgrp1 = df['Service 1'].groupby(['Service Type'])
----> 2 dfgrp1 = dfgrp1.to_frame()
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\groupby\groupby.py:904, in GroupBy.__getattr__(self, attr)
901 if attr in self.obj:
902 return self[attr]
--> 904 raise AttributeError(
905 f"'{type(self).__name__}' object has no attribute '{attr}'"
906 )
AttributeError: 'DataFrameGroupBy' object has no attribute 'to_frame'
P.S. I have multiple sheets in the excel workbook I don't think that would be a problem but just mentioning it in case it does affect.
Apply aggregation to the grouped result first.
for instance, dfgrp1 what does it produces when you print it? an object reference, which you cannot make into frame.
However, the result that you see as result of groupby, employing agregation, will allow you to use to_frame()
Hi guys is am getting this error:
AttributeError: 'numpy.float64' object has no attribute 'index'
The traceback looks like this:
AttributeError Traceback (most recent call last)
<ipython-input-50-dfcbcabe20ea> in <module>()
2 for name, df in all_data.items():
3 top_10 = df.mean().dropna().sort_values().iloc[-10]
----> 4 top_10_columns[name] = top_10.index
While running the following code:
top_10_columns = {}
for name, df in all_data.items():
top_10 = df.mean().dropna().sort_values().iloc[-10]
top_10_columns[name] = top_10.index
You are accidentally not getting the "top 10" items when you do .iloc[-10], but just the 10th to last item. So top_10 is a single value of type numpy.float64. Giving iloc a range should fix it. .iloc[0:10] or .iloc[-10:] depending on whether your sort is ascending or descending and you want to get either the first ten items (.iloc[0:10]) or the last ten items (.iloc[-10:]).
You are trying to assign to an array, but Python is interpreting top_10_columns as a float. Above your for loop you must declare it as an array i.e top_10_columns = []
how can i read data from a csv with chnunksize and names?
I tried this:
sms = pd.read_table('demodata.csv', header=None, names=['label', 'good'])
X = sms.label.tolist()
y = sms.good.tolist()
and it worked totaly fine. But if try this, i'll get an error:
sms = pd.read_table('demodata.csv', chunksize=100, header=None, names=['label', 'good'])
X = sms.label.tolist()
y = sms.good.tolist()
And i get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-18-e3f35149ab7f> in <module>()
----> 1 X = sms.label.tolist()
2 y = sms.good.tolist()
AttributeError: 'TextFileReader' object has no attribute 'label'
Why does it work in the first but not in the second place?
I have the following code:
from pyspark.sql import Row
z1=["001",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,30,41,42,43]
print z1
r1 = Row.fromSeq(z1)
print (r1)
Then I got error:
AttributeError Traceback (most recent call last)
<ipython-input-6-fa5cf7d26ed0> in <module>()
2 z1=["001",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,30,41,42,43]
3 print z1
----> 4 r1 = Row.fromSeq(z1)
5
6 print (r1)
AttributeError: type object 'Row' has no attribute 'fromSeq'
Anyone know what I might have missed? Thanks!
If you don't provide names just use tuple:
tuple(z1)
This is all what is needed to build correct DataFrame