# 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()
暂无答案!
目前还没有任何答案,快来回答吧!