Export Multiple GB PySpark dataframe to CSV, np or pickle - python

I have this large dataset around 6gb and have processed and cleaned the data using PySpark and now want to save it so I can use it elsewhere for machine learning uses
I am trying to find the fastest way of saving the datasets.
I followed this link, but its taking so long to save the csv or the parquet.
How to export a table dataframe in PySpark to csv?
Please can someone provide some information on how I can do this

Related

Is there a way to read a general ledger file into a Dataframe in python?

I have two excel files which are in general ledger format, I am trying to open them as dataframes so I can do some analysis, specifically look for duplicates. I tried opening them using
pd.read_excel(r"Excelfile.xls)in pandas. The files are being read but when I use df.head() , I am getting nans for all the records and columns as well. Is there a way to load the data in general ledger format into a data frame?
This is how the dataset looks like in the Jupyter notebook
This is what the dataset looks like in excel
I am new to stack overflow and I haven't learnt its full functionality to upload part of a dataset yet
I hope the images help in describing my situation

Spark, small excel files, Pandas or Pyspark for performance?

I'm working with small Excel files (10 000 rows or less) in spark (Databricks).
I need to do some transformations on the excel file and usually I use pandas to read in the file, convert to spark dataframe and then do transformations. But since learning more about Spark distributed architecture I'm thinking that this is not good for performance for such small files?
Should I just do all the transformations with Pandas (forcing it to run only on the driver node) and then converting to spark dataframe only when needed or does it not really matter?

Is it possible to append to an existing Feathers format file?

I am working on a very huge dataset with 20 million+ records. I am trying to save all that data into a feathers format for faster access and also append as I proceed with me analysis.
Is there a way to append pandas dataframe to an existing feathers format file?
Feather files are intended to be written at once. Thus appending to them is not a supported use case.
Instead I would recommend to you for such a large dataset to write the data into individual Apache Parquet files using pyarrow.parquet.write_table or pandas.DataFrame.to_parquet and read the data also back into Pandas using pyarrow.parquet.ParquetDataset or pandas.read_parquet. These functions can treat a collection of Parquet files as a single dataset that is read at once into a single DataFrame.

python pandas memory errors while working with big CSV files

I'm having memory problems while using Pandas on some big CSV files (more than 30 million rows). So, I'm wondering what is the best solution for this? I need to merge couple big tables. Thanks a lot!
Possible duplicate of Fastest way to parse large CSV files in Pandas.
The inference is, if you are loading the csv file data often, then a better way would be to parse it once (with conventional read_csv) and store it in HDF5 format. Pandas (with PyTables library), provides an efficient way to handle this issue [docs].
Also, the answer to What is the fastest way to upload a big csv file in notebook to work with python pandas? shows you the timed execution (timeit) of sample dataset with csv vs csv.gz vs Pickle vs HDF5 comparison.

most efficient I/O setup between Stata and Python (Pandas)

I am using Stata to process some data, export the data in a csv file and load it in Python using the pandas read_csv function.
The problem is that everything is so slow. Exporting from Stata to a csv file takes ages (exporting in the dta Stata format is much faster), and loading the data via read_csv is also very slow. Using the read_stata pandas function is even worse.
I wonder is there are any other options? Like exporting a format other than csv? My csv dataset is approx 6-7 Gb large.
Any help appreciated
Thanks
Pretty efficient pd.read_stata()/.to_stata(), see here

Categories