Posts

Showing posts with the label Excel

Reading and Writing Data in Pandas:

Reading and Writing Data in Pandas: Pandas provides several functions to read and write data in different formats. Here are some commonly used functions: Reading CSV files: CSV (Comma Separated Values) is a file format used to store tabular data, such as spreadsheets. The read_csv() function in Pandas is used to read data from a CSV file. Here's an example: python Copy code import pandas as pd  # Read a CSV file   df = pd.read_csv( 'data.csv' )  # Display the first 5 rows of the data   print (df.head()) In this example, data.csv is the name of the file that we want to read. The read_csv() function reads the file and stores it in a DataFrame, which is then displayed using the head() function. Writing CSV files: Once you have processed the data using Pandas, you may want to write it back to a CSV file. The to_csv() function in Pandas is used to write data to a CSV file. Here's an example: python Copy code import pandas as pd  # Create a DataFrame   data = { '