python—我没有得到所需的输出我想从文件夹中提取特定的文件集,但输出只是提供的索引

tv6aics1  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(176)

# Folder path

folders = glob.glob("F:/TXTXT*")

# Dataframe

df = pd.DataFrame(columns={'Country','Speech','Session','Year'})

# Read speeches by India

i = 0 

for files in folders:
    speech = glob.glob(files+'\IND*.txt')

    with open(speech[0],encoding='utf8') as f:
        # Speech
        df.loc[i,'Speech'] = f.read()
        # Year 
        df.loc[i,'Year'] = speech.split('_')[-1].split('.')[0]
        # Session
        df.loc[i,'Session'] = speech.split('_')[-2]
        # Country
        df.loc[i,'Country'] = speech.split('_')[0].split("\\")[-1]

        # Increment counter
        i += 1 

df.head()

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题