Home > Net >  Transforming rows to columns -> first column not recognized
Transforming rows to columns -> first column not recognized

Time:04-19

I am trying to extract emoji counts from text and currently struggle in giving the output columns titles. If I try to assign columns, it would only recognize one column (the count), not the emoji column itself, which is the first one, so I assume the issue lies there? I thought with setting the index to 0 it would solve that, but apparently I misunderstood that. Would I need to convert the df into a series to recognize the first and the second columns as such and be able to name them? (Lets same into: columns=['emoji','count']

MWE:

import csv
import re
import pandas as pd
import emoji
import regex
from collections import Counter

def split_count(text):
    emoji_list = []
    data = regex.findall(r'\X', text)
    for word in data:
        if any(char in emoji.UNICODE_EMOJI['en'] for char in word):
            emoji_list.append(word)
    
    return emoji_list


df = pd.DataFrame([{'id':1432691762007400458,'created_at':"2021-08-31T13:08:28.000Z",'text':"9月1日㈬は…           
  • Related