在Excel中清理Twitter数据

2024-04-29 11:11:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为学校做一个项目,但现在有了在线教学,很难得到帮助。我在excel中有一个数据集,有一些链接和表情需要删除

这就是我现在的数据。我想摆脱https://t.co/。。。。。。。链接、表情符号和一些奇怪的角色

screenshot of twitter data

有人对如何在excel中执行此操作有任何建议吗?或者python


Tags: 数据项目https角色链接excel建议表情
2条回答

根据这个{a1},我相信你可以做这样一个函数:

def checkChars(inputString):
    outputString = ""
    allowedChars = [" ", "/", ":", ".", ",",";"] # The characters you want to include
    for l in inputString:
        if l.isalnum() or l in allowedChars: # This line will check if the character is alphanumeric or is in your allowed character list
            outputString += l
    return outputString

如果有帮助,请告诉我!干杯

我不知道如何在Excel中执行此操作,但是,您可以轻松地将Excel文件加载到“pandas.dataFrame”中,然后使用正则表达式忽略非ascii字符:

file_path = '/some/path/to/file.xlsx'
df = pd.read_excel(file_path , index_col=0) 
df = df.replace(r'\W+', '', regex=True)

在这里,您可以找到关于loading an Excel file into a dataframe的额外解释 在这里你可以阅读关于more ways to ignore non-ascii chars in ^{}

相关问题 更多 >