Skip to main content

Posts

Showing posts with the label csv

Writing and Reading CSV Files with Python Pandas

Pandas, a powerful Python library for data manipulation and analysis, provides a comprehensive set of methods for reading and writing CSV (Comma-Separated Values) files. These methods are designed to be efficient, flexible, and easy to use. Writing Data to CSV Files To write data to a CSV file using Pandas, you can use the to_csv() method attached to the DataFrame or Series object. This method takes the filename as its first argument and supports various options to control the formatting and behavior of the output CSV file. import pandas as pd # Create a DataFrame df = pd.DataFrame({'Name': ['John', 'Mary', 'Bob'], 'Age': [25, 30, 35]}) # Write the DataFrame to a CSV file df.to_csv('data.csv', index=False) Reading Data from CSV Files To read data from a CSV file into a Pandas DataFrame, you can use the read_csv() function. This function takes the filename as its first argument and also supports various options to control the parsing an...

Writing Data to Excel Sheets with Python Pandas

Pandas, a powerful Python library for data manipulation and analysis, provides seamless integration with Microsoft Excel. Writing data to Excel sheets using Pandas is a common task in data analysis, enabling you to export your data into a widely accessible and editable format. In this blog post, we will explore the various methods for writing data to Excel sheets using Pandas. We will cover the syntax, usage, and best practices for each method, providing code examples and practical applications. Methods for Writing Data to Excel Sheets Pandas offers two primary methods for writing data to Excel sheets: to_excel(): Writes a DataFrame or Series to an Excel sheet, creating a new file or appending to an existing one. ExcelWriter: Provides a more advanced interface for writing data to Excel sheets, allowing for finer control over the writing process. 1. Using the to_excel() Method The to_excel() method is the most straightforward way to write data to an Excel sheet. It takes a filename as i...

Tried to open a very big CSV file in excel

Have you tried opening a very big csv file with excel?  I tried to open a csv file with 5million rows of data using Microsoft Excel : 1,048,576 rows limit . 1 million row limit ,I was aware of this. Not all the data was loaded , even got a notification modal stating this. 32,767 character per cell , this I was not aware of. After opening a file which exceed this limit , new rows were displayed and looked like a mess. But the file was properly formatted when opened with notepad. This one is obvious but formulas and filters were very slow (given the size of the data ,expected). Why I was required to open a file with over 5million rows in the first place ? I was actively trying to learn machine learning and tried to build dataset for supervised learning. I wanted to open the file to mark classes and values - for training classification and regression models. Workarounds I did include : filtered and removed currently unused rows . This cut the size by almost half. split the files into ...

Topics

Show more