Difference between revisions of "Pandas notes"
(→Plot options) |
|||
Line 1: | Line 1: | ||
{{TocRight}} |
|||
Using Python Pandas package for data analysis. Leo's notes. |
Using [http://pandas.pydata.org/ Python Pandas package] for data analysis. Leo's notes. |
||
== Data manipulation == |
|||
Import data from a CSV file to a dataframe |
|||
df = pd.read_csv("filename.csv") |
|||
Filter the data by a field value |
|||
df2 = df.loc[df['Tagid'] == "1234"] |
|||
Get all unique values (for example, for the Tagid field) |
|||
allTags = df.Tagid.unique() |
|||
Pivot the table, where the values become columns. For example, to create a plot that uses unique values (of Tagid) as the series. |
|||
dfTags = df.pivot(columns='Tagid', values='RSSI') |
|||
== Plot options == |
== Plot options == |
Revision as of 09:45, 26 October 2017
Contents |
Using Python Pandas package for data analysis. Leo's notes.
Data manipulation
Import data from a CSV file to a dataframe
df = pd.read_csv("filename.csv")
Filter the data by a field value
df2 = df.loc[df['Tagid'] == "1234"]
Get all unique values (for example, for the Tagid field)
allTags = df.Tagid.unique()
Pivot the table, where the values become columns. For example, to create a plot that uses unique values (of Tagid) as the series.
dfTags = df.pivot(columns='Tagid', values='RSSI')
Plot options
Define the colors of the plot data
df.plot(color="rgbk")
Different plot types (markers)
df.plot(marker='.')
Limit the X axis values:
df.plot(xlim=(0,4000))
Naming the axis
ax = df.plot() ax.set_ylabel(AntNames[x])
Placement of the legend (Below-left of the plot)
df.plot().legend(loc='upper left', bbox_to_anchor=(0, 0))
Removing the legend
ax = df.plot() ax.legend_.remove()