diff --git a/src/pages/pandas.js b/src/pages/pandas.js index 6172466c46..58a0afdb48 100644 --- a/src/pages/pandas.js +++ b/src/pages/pandas.js @@ -5,8 +5,9 @@ import Container from 'react-bootstrap/Container'; import Contact from '../components/Contact'; import Row from 'react-bootstrap/Row'; import ChartFamilySection from '../components/ChartFamilySection'; +import ChartImage from '../components/ChartImage'; import { Link } from 'gatsby'; -import { Plotly } from '../components/MiscellaneousLogos'; +import { Pandas } from '../components/MiscellaneousLogos'; import { Col } from 'react-bootstrap'; import CodeChunk from '../components/CodeChunk'; import Spacing from '../components/Spacing'; @@ -16,13 +17,44 @@ import ChartImageContainer from '../components/ChartImageContainer'; const chartDescription = ( <>

- Beyond its powerful data manipulation capabilities, Pandas offers - convenient plotting methods, enabling users to visualize data directly - from DataFrame and Series objects. + Pandas is a popular open-source Python + library used for data manipulation and analysis. It provides data structures and functions + that make working with structured data, such as tabular data (like Excel spreadsheets or + SQL tables), easy and intuitive. +

+

+ Although not best known for this functionality, Pandas can be used to create graphs and visualize + data, thanks to its lightweight syntax and matplotlib functions.

); +const quickCode = `# library +import pandas as pd +import matplotlib.pyplot as plt + +# Create data +values=[12, 11, 9, 13, 14, 16, 14, 15, 18, 17, 19, 20] +df=pd.DataFrame({'x': range(1,13), 'y': values }) + +# plot +df.plot('x', 'y') +plt.show() +`; + +const plotApi = `df.plot('x', 'y', kind='line') +plt.show() +`; + +const funcnameApi = `df.line('x', 'y') +plt.show() +`; + +const plotFuncnameApi = `df.plot.line('x', 'y') +plt.show() +`; + + export default function Plotlys() { return ( -

This section is under construction and will be available soon.

+

⏱ Quick start

+ + +

+ Pandas is the most famous python data + manipulation and cleaning library. However, it can also be used to + create charts and graphs. Pandas plotting features are a wrapper + around the matplotlib{' '} + library, which is the most popular python library for data visualization. +

+

+ The plot function is the most basic function to + create a chart with pandas. It is a wrapper around the{' '} + matplotlib.pyplot.plot function. +

+ + + + + + +
+ {quickCode} +
+ + + + +

+ + Three distinct syntaxes +

+

+ There are 3 ways to build a chart with pandas: the{' '} + plot method, the function name method + (like line, bar or hist) and the plot + function name method. +

+

+ ➡️ plot method +

+

+ In this case, we have to specify the kind of chart we + want to create. The plot method is a wrapper around the{' '} + matplotlib.pyplot.plot function. The kind{' '} + argument is used to specify the type of chart we want to create. +

+ {plotApi} +
+
+

+ ➡️ function name method +

+

+ The function name method is a bit more straightforward. We just have + to call the right function name to create the chart we want. Matplotlib has + various functions to create different types of charts. For example, the + line function is used to create line charts. +

+ + {funcnameApi} + +
+
+

+ ➡️ plot + function name method +

+

+ This method is a combination of the previous two. We use the{' '} + plot method and need the function name + right after it. +

+ + {plotFuncnameApi} + +
+
+ +

+ The function name method is the most straightforward and + the one we recommend. Most posts on the gallery use this method. +

+ +
+ + + + +

+ + Chart examples with Pandas +

+

+ Pandas offers a wide range of nice charts. Here is a selection of + examples that you can find on the gallery. Click on the images to see the code! +

+ + + + + + + + + + + + + + +
@@ -60,70 +240,6 @@ export default function Plotlys() { ); } -const quickCode = `# Load plotly -import plotly.graph_objects as go - -# Sample data -x = [1.5, 2.9, 3, 4.2, 5.6] -y = [2.2, 13.3, 4.4, 55.3, 52.1] - -# Initialize a figure -fig = go.Figure() - -# Add the scatter trace -fig.add_trace(go.Scatter( - x=x, # Variable in the x-axis - y=y, # Variable in the y-axis - mode='markers', # This explicitly states that we want our observations to be represented by points -)) - -# Show -fig.show() -`; - -const codeInstall = `pip install plotly`; -const saveCode = `fig.write_html("the/path/to/chart-name.html")`; -const embedCode = ``; -const plotlyExpressCode = `# import the plotly express library -import plotly.express as px -# Some dummy data -categories = ['A', 'B', 'C', 'D', 'E'] -values = [15, 22, 18, 12, 28] - -# Plot -fig = px.bar( - x=categories, - y=values, -) - -fig.show() -`; - -const plotlyGoCode = `# import the plotly graph objects lib -import plotly.graph_objects as go - -# Some dummy data -categories = ['A', 'B', 'C', 'D', 'E'] -values = [15, 22, 18, 12, 28] - -# Create a bar chart using the Graph Object API -fig = go.Figure(data=[go.Bar(x=categories, y=values)]) - -# Update layout -fig.update_layout( - title="Simple Bar Chart", - xaxis_title="Categories", - yaxis_title="Values") - - -fig.show() -`; diff --git a/static/graph/quick-pandas.png b/static/graph/quick-pandas.png new file mode 100644 index 0000000000..026385ad66 Binary files /dev/null and b/static/graph/quick-pandas.png differ