How to read and save multi-format data files with Pandas
This article will explain in detail how to read and save multi-format data files in Pandas. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Code snippet:
# Pandas file reads and saves data to multiple format files # In [23]: import pandas as pd# In [24]: df = pd.read_csv ('data_price.csv') df.head () # set the index column to be saved as a new csv format file # In [25]: df.set_index (' Date') Inplace=True) df.to_csv ('data_pricenew.csv') # read the new csv file # In [26]: df = pd.read_csv (' data_pricenew.csv') df.head () # set the first column index column # In [27]: df = pd.read_csv ('data_pricenew.csv' Index_col=0) df.head () # rename column # In [28]: df.columns= ['NewPrices'] df.head () # Save as csv file Does not include column name # In [29]: df.to_csv ('data_pricenew2.csv',header=False) # In [30]: df = pd.read_csv (' data_pricenew2.csv',\ names= ['Date','Prices']) Index_col=0) df.head () # Save as html format file # In [31]: df.to_html ('dataprice.html') # for the file reading and saving format of pandas, see the official website address: # https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html
On "Pandas how to achieve multi-format data file reading and saving" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.