我遇到了一个问题,每次运行我的程序(从 .csv 文件读取数据帧)时,都会出现一个名为“未命名”的新列。
运行 3 次后的示例输出列 -
Unnamed: 0 Unnamed: 0.1 Subreddit Appearances
Run Code Online (Sandbox Code Playgroud)
这是我的代码。对于每一行,“未命名”列仅增加 1。
df = pd.read_csv(Location)
while counter < 50:
#gets just the subreddit name
e = str(elem[counter].get_attribute("href"))
e = e.replace("https://www.reddit.com/r/", "")
e = e[:-1]
if e in df['Subreddit'].values:
#adds 1 to Appearances if the subreddit is already in the DF
df.loc[df['Subreddit'] == e, 'Appearances'] += 1
else:
#adds new row with the subreddit name and sets the amount of appearances to 1.
df = df.append({'Subreddit': e, 'Appearances': …Run Code Online (Sandbox Code Playgroud)