<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Forum Pasja Informatyki - Najnowsze z tagiem typerror</title>
<link>https://forum.pasja-informatyki.pl/tag/typerror</link>
<description>Powered by Question2Answer</description>
<item>
<title>TypeError: normalize() argument 2 must be str, not Series z string dataframe</title>
<link>https://forum.pasja-informatyki.pl/411068/typeerror-normalize-argument-2-must-be-str-not-series-z-string-dataframe</link>
<description>

&lt;p&gt;Mam dataframe zawierającą wiadomości na każdy dzień.&amp;nbsp; zawierającą wiadomości na każdy dzień. Próbuję analizować intensywność uczuć na dany dzień. Można powiedzieć, że ogólne odczucie dnia z wiadomości jest pozytywne, negatywne lub neutralne. Oto ramka danych `df_news` :&lt;/p&gt;



&lt;pre class=&quot;brush:python;&quot;&gt;
    	Date	name
    0	2017-10-20	Gucci debuts art installation at its Ginza sto...
    1	2018-08-01	Gucci Joins Paris Fashion Week for Its Spring ...
    2	2018-04-20	Gucci launches its new creative hub Gucci ArtL...
    3	2017-10-20	Gucci to launch homeware line Gucci Decor - CP...
    4	2017-12-07	GUCCI opens new store at Miami Design District...
    5	2018-01-12	Gucci opens Gucci Garden in Florence - LUXUO
    6	2018-02-26	GUCCI's wild experiment with the Fall Winter 2...
    7	2018-08-09	Gucci Revamped London Flagship Store | The Imp...
    8	2018-08-01	Alessandro Michele Announces new Gucci Home co...
    9	2017-10-20	Before He Picks Up the CFDA’s International Aw...
&lt;/pre&gt;



&lt;p&gt;Próbował uzyskać intensywność uczuć za pomocą następującego kodu, który używa [SentimentIntensityAnalyzer] [1] z [nltk.sentiment.vader] [2]:&lt;/p&gt;



&lt;pre class=&quot;brush:python;&quot;&gt;
    from nltk.sentiment.vader import SentimentIntensityAnalyzer
    import unicodedata
    sid = SentimentIntensityAnalyzer()
    for date, row in df_news.T.iteritems():
        try:
            sentence = unicodedata.normalize('NFKD', df_news.loc[date, 'name']).encode('ascii','ignore')
            #print((sentence))
            ss = sid.polarity_scores(str(sentence))
            df_news.set_value(date, 'compound', ss['compound'])
            df_news.set_value(date, 'neg', ss['neg'])
            df_news.set_value(date, 'neu', ss['neu'])
            df_news.set_value(date, 'pos', ss['pos'])
        except TypeError:
            print(df_news.loc[date, 'name'])
            print(date)
&lt;/pre&gt;



&lt;p&gt;Jednak otrzymuję TypeError dla niektórych dat. Dzięki &quot;try catch&quot; nie bierze tego pod uwagę i rysuje mi następującą tabelę:&lt;/p&gt;



&lt;pre class=&quot;brush:python;&quot;&gt;
    	name	compound	neg	neu	pos
    Date					
    2017-10-20	Gucci debuts art installation at its Ginza sto...				
    2018-08-01	Gucci Joins Paris Fashion Week for Its Spring ...				
    2018-04-20	Gucci launches its new creative hub Gucci ArtL...	0.4404	0	0.756	0.244
    2017-10-20	Gucci to launch homeware line Gucci Decor - CP...				
    2017-12-07	GUCCI opens new store at Miami Design District...	0	0	1	0
    2018-01-12	Gucci opens Gucci Garden in Florence - LUXUO	0	0	1	0
    2018-02-26	GUCCI's wild experiment with the Fall Winter 2...	0	0	1	0
    2018-08-09	Gucci Revamped London Flagship Store | The Imp...	0.3182	0	0.602	0.398
    2018-08-01	Alessandro Michele Announces new Gucci Home co...				
    2017-10-20	Before He Picks Up the CFDA’s International Aw...				
&lt;/pre&gt;



&lt;p&gt;Ale kiedy usunę try catch, aby zrozumieć, dlaczego to się nie udało, pojawia się następujący błąd:&lt;/p&gt;



&lt;pre class=&quot;brush:python;&quot;&gt;
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    &amp;lt;ipython-input-26-2e9dbfc62bce&amp;gt; in &amp;lt;module&amp;gt;
          4 for date, row in df_news.T.iteritems():
          5 #    try:
    ----&amp;gt; 6     sentence = unicodedata.normalize('NFKD', df_news.loc[date, 'name']).encode('ascii','ignore')
          7     #print((sentence))
          8     ss = sid.polarity_scores(str(sentence))
    
    TypeError: normalize() argument 2 must be str, not Series&lt;/pre&gt;



&lt;p&gt;Wtedy pomyślałem, że problem dotyczy linii, które nie były ciągami, ale. Na przykład z pierwszym:&lt;/p&gt;



&lt;pre class=&quot;brush:python;&quot;&gt;
    &amp;gt;&amp;gt;&amp;gt;type(df_news['name'][0])
    str&lt;/pre&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/411068/typeerror-normalize-argument-2-must-be-str-not-series-z-string-dataframe</guid>
<pubDate>Fri, 01 Feb 2019 11:36:51 +0000</pubDate>
</item>
</channel>
</rss>