export-to-csv

Using to_csv to generate a txt file without double quoting

Using to_csv to generate a txt file without double quoting Question: I am trying to export pandas dataframe in txt. Some of data contains double quotes and I can’t get it done correctly : Desired output is a txt file of one column with this format No Header xxxxxxxx BG {"xxxxxx":"xxxx","xxxxx":"xxxxxx"} yyyyyy BG {"yyyy":"yyyyy","yyyy":{"yyyy":""},"yyyy":{"yyyyy": {"yyyy":"yyyy","yyyyy":"yyyy"}},"yyy":"yyy","yyyy":"yyy","yyy":"yyyyyy","yyyy":"yyyyyy"} …

Total answers: 1

DateTime when saving pandas dataframe to CSV

DateTime when saving pandas dataframe to CSV Question: Background: Apparently Google doesn’t have a straight answer to a very basic question, so here goes… I have a pandas df with a Open Date column [Dtype = object] which (when previewing df) is formatted yyyy-mm-dd, which is the format I want, great! Not so great however, …

Total answers: 1

how to convert lmd file to csv? [Flow Cytometry data]

how to convert lmd file to csv? [Flow Cytometry data] Question: lmd file extension is often used for generating flow cytometry data. But this couldn’t be directly used for processing either in R or Python. Is there a way to somehow convert it to csv or some renowned format? Asked By: Sachin || Source Answers: …

Total answers: 3

Remove leading comma in header when using pandas to_csv

Remove leading comma in header when using pandas to_csv Question: By default to_csv writes a CSV like ,a,b,c 0,0.0,0.0,0.0 1,0.0,0.0,0.0 2,0.0,0.0,0.0 But I want it to write like this: a,b,c 0,0.0,0.0,0.0 1,0.0,0.0,0.0 2,0.0,0.0,0.0 How do I achieve this? I can’t set index=False because I want to preserve the index. I just want to remove the …

Total answers: 3

how to convert pdf file to excel file using python

how to convert pdf file to excel file using python Question: I want to convert a pdf file into excel and save it in local via python. I have converted the pdf to excel format but how should I save it local? my code: df = (“./Downloads/folder/myfile.pdf”) tabula.convert_into(df, “test.csv”, output_format=”csv”, stream=True) Asked By: Yuvraj Singh …

Total answers: 6

Exporting a PostgreSQL query to a csv file using Python

Exporting a PostgreSQL query to a csv file using Python Question: I need to export some rows from a table in a PostgreSQL database to a .csv file using a Python script: #!/usr/bin/python # -*- coding: utf-8 -*- import sys, psycopg2 … conn = psycopg2.connect(“dbname=dbname user=user password=password”) cur = conn.cursor() sql = “copy (SELECT * …

Total answers: 4

Pandas to_csv() checking for overwrite

Pandas to_csv() checking for overwrite Question: When I am analyzing data, I save my dataframes into a csv-file and use pd.to_csv() for that. However, the function (over)writes the new file, without checking whether there exists one with the same name. Is there a way to check whether the file already exists, and if so, ask …

Total answers: 3

Writing large Pandas Dataframes to CSV file in chunks

Writing large Pandas Dataframes to CSV file in chunks Question: How do I write out a large data files to a CSV file in chunks? I have a set of large data files (1M rows x 20 cols). However, only 5 or so columns of the data files are of interest to me. I want …

Total answers: 3

How to export a table dataframe in PySpark to csv?

How to export a table dataframe in PySpark to csv? Question: I am using Spark 1.3.1 (PySpark) and I have generated a table using a SQL query. I now have an object that is a DataFrame. I want to export this DataFrame object (I have called it “table”) to a csv file so I can …

Total answers: 9