Remove ends of string entries in pandas DataFrame column

前端 未结 4 1187
盖世英雄少女心
盖世英雄少女心 2020-12-30 05:35

I have a pandas Dataframe with one column a list of files

import pandas as pd
df = pd.read_csv(\'fname.csv\')

df.head()

filename    A    B    C
fn1.txt   2         


        
4条回答
  •  遥遥无期
    2020-12-30 06:09

    You can use str.rstrip to remove the endings:

    df['filename'] = df['filename'].str.rstrip('.txt')
    

    should work

提交回复
热议问题