When I use pandas read_sql to read from mysql, it returns rows with row number as first column as given below. Is this possible to avoid row numbers?
Advertisement
Answer
You can use False
as the second parameter to exclude indexing.
Example
JavaScript
x
3
1
df.to_csv('filename.csv', index = False, encoding='utf-8')
2
print(df)
3
or
JavaScript
1
3
1
df.toPandas().to_csv('filename.csv', index=False, encoding='utf-8')
2
print(df)
3
Use this function to guide you
JavaScript
1
2
1
DataFrame.to_csv(self, path_or_buf=None, sep=', ', na_rep='', float_format=None, columns=None, header=True, index=True, index_label=None, mode='w', encoding=None, compression='infer', quoting=None, quotechar='"', line_terminator=None, chunksize=None, date_format=None, doublequote=True, escapechar=None, decimal='.')
2
You can read more about this here -> Pandas DataFrame: to_csv() function