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
df.to_csv('filename.csv', index = False, encoding='utf-8') print(df)
or
df.toPandas().to_csv('filename.csv', index=False, encoding='utf-8') print(df)
Use this function to guide you
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='.')
You can read more about this here -> Pandas DataFrame: to_csv() function