pandas csv dataframe code example
Example 1: command to read file in python using pandas
import panda as pd
file_csv = pd.read_csv("file path")
file_excel = pd.read_excel("file path")
file_json = pd.read_json("file path")
file_html = pd.read_html("file path")
file_localClipboard = pd.read_clipboard("file path")
file_MSExcel = pd.read_excel("file path")
file_HDF5 = pd.read_hdf("file path")
file_Feather = pd.read_feather("file path")
file_msgpack = pd.read_msgpack("file path")
file_stata = pd.read_stata("file path")
file_SAS = pd.read_sas("file path")
file_paythonPickle = pd.read_pickle("file path")
file_SQL = pd.read_sql("file path")
file_google_big_query = pd.read_gbq("file path")
Example 2: how to set up dataframe from csv
import pandas as pd
column_names = ['sepel lengh', 'sepel width', 'petal lengh', 'petal width', 'class']
iris = pd.read_csv('iris.csv', names=column_names)
print(iris)
Example 3: pandas go through csv file
data = pd.read_csv(
"data/files/complex_data_example.tsv",
sep='\t'
quotechar="'",
dtype={"salary": int},
usecols=['name', 'birth_date', 'salary'].
parse_dates=['birth_date'],
skiprows=10,
na_values=['.', '??']
)
Example 4: save dataframe as csv
df.to_csv(r'Path where you want to store the exported CSV file\File Name.csv', index = False)
Example 5: read a csv file in pandas
you should be in the same dir as .py file
df = pd.read_csv('your_file_name.csv')