Since your df
is just using a default range index, I suggest ignoring the index column with index=False
when saving:
df.to_csv('data.csv', index=False)
Otherwise whenever someone tries to load your data with read_csv('data.csv')
, they'll run into the common and annoying "Unnamed: 0" issue:
How to get rid of "Unnamed: 0" column in a pandas DataFrame read in from CSV file?
I have a situation wherein sometimes when I read a csv from df, I get an unwanted index-like column named Unnamed: 0.
This is very annoying! Does anyone have an idea on how to get rid of this?
Yes, they can fix it by specifying read_csv('data.csv', index_col=0)
, but it's just an unnecessary annoyance that can be circumvented at save time.
Also some formatting nits:
- Don't use spaces around default params (e.g.,
class_ = 'product_pod'
->class_='product_pod'
) - Don't mix single/double quotes unless needed (e.g.,
"lxml"
is double while everything else is single) - Use a space after commas (e.g.,
range
anddata.append
have some missing spaces)