My Coding >
Programming language >
Python >
Python libraries and packages >
Python Panda
Python Panda (Page: 7)Go to Page:
This will be very long list of most useful commands with panda, usually accompanied with some examples, if it is necessary for clear understanding. At he beginning I will introduce example sets and will continue to work only with them. Pandas cheat sheet startingFor all your python code you need to load numpy and pandas libraries first. Also, defined here data sets we will use later for examples. Aslo we will use name df for our data-frame variable
Pandas importing datadf = pd.read_csv('file_name.csv') – read CSV fileRead CSV file. Important parameters are:
df = pd.read_excel('file_name.xlsx') – read EXEL filedf = read_sql(query, connection_object) – read SQL table-specificThis function can read directly from many different SQL databases. This is an example how to read from MySQL
df = pd.read_json(json_string) – read from JSON filedf = pd.read_html(url) – read table from URL givenpd.read_html(url) can read tables directly from HTM, but usually a lot of further cleaning required. df = pd.read_table(filename) – read table from text fileThis function is very similar to read_csv fucntion df = pd.read_clipboard() - read content of clipboardRead content of clipboard and send to read_table() function Pandas exporting datadf = df.to_csv(filename) Write to a CSV filedf = df.to_excel(filename) Write to an Excel fileBefore writing to excel, you need to specify the engine
df = df.to_sql(table_name, connection_object) - Write to a SQL tabledf = df.to_json(filename) - Write to a file in JSON formatView and inspectdf.head(n) – first n linesdf.tail(n) – last n linesnrow, ncol = df.shape – number of rows and columns
df.info() - Index. DataType and Memory informationStatistical information about DataFramedf.describe() - Summary statistic for numerical columnsGive basic statistic for all numerical columns, like number of elements, mean, standard deviation, minimal, maximal values and 25% 50% 75% quantilies
df.mean() - mean of all numerical columns
df.corr() - correlation between columns in a DataFrameThis example is not very demonstrative, because all columns are “parallel” with 100% correlation.
df.count() - number of non-null values in each DataFrame columnCount any present numbers. 0 is counted also, this is not NULL df.max() -highest value in each columndf.min() - lowest value in each columndf.median() - median of each columndf.std() - Returns the standard deviation of each columnGo to Page: 1; 2; 3; 4; 5; 6; 7; 8;
|
Last 10 artitles
9 popular artitles
|
|
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |