【问题标题】:Cleaning Twitter Data in Excel在 Excel 中清理 Twitter 数据
【发布时间】:2021-10-29 14:22:27
【问题描述】:

我正在为学校做一个项目,但现在有了在线指导,获得帮助变得更加困难。我在 excel 中有一个数据集,我需要删除一些链接和表情符号。

这就是我的数据现在的样子。我想去掉https://t.co/.......链接、表情符号和一些奇怪的字符。

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

【问题讨论】:

    标签: python excel twitter


    【解决方案1】:

    我不确定如何在 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 dataframe

    【讨论】:

      【解决方案2】:

      根据这个reference,我相信你可以做这样的功能:

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-29
        • 1970-01-01
        • 2017-04-02
        • 2022-12-21
        • 2017-07-03
        • 1970-01-01
        • 1970-01-01
        • 2023-01-14
        相关资源
        最近更新 更多