Bugs 🐜 / Jul 20 2018
Pandas Dataframes & Cufflinks Plots
Pandas Dataframes & Cufflinks Plots
1. Setup
1.
Setup
%%sh pip install pandas xlrd cufflinks &> /dev/null
#plotly.offline doesn't push your charts to the clouds import plotly.offline as pyo #allows us to create the Data and Figure objects from plotly.graph_objs import * #plotly.plotly pushes your charts to the cloud import plotly.plotly as py import plotly.figure_factory as ff from plotly import tools from plotly.figure_factory import create_table as tbl import pandas as pd import numpy as np import warnings import cufflinks as cf cf.go_offline() cf.set_config_file(theme='white') warnings.filterwarnings('ignore')
def get_data(fname=Original-tweets_new.xlsx↩, sheet_name='Clean Data', required_fields=['Tweet', 'S/A'], binary=False): df = pd.read_excel(fname, sheet_name=sheet_name, encoding='utf-8') if binary: df = df[(df['S/A'] == 'positive') | (df['S/A'] == 'negative')] return df[required_fields] senti_df = get_data(required_fields=['Tweet', 'Annotation/Type', 'S/A'])
# convert the 'S/A' column to lowercase to eliminate differences between Positive and positive .. etc senti_df.iloc[:, 1:] = senti_df.iloc[:, 1:].apply(lambda x: x.str.lower()) senti_df.rename(columns={'Annotation/Type': 'Annotation'}, inplace=True)
2. Dataframe Display
2.
Dataframe Display
2.1. Our Display
2.1.
Our Display
This should display a table, not just text, see nbviewer for a comparison.
senti_df.head()
2.2. Reference
2.2.
Reference
3. Cufflinks Plot
3.
Cufflinks Plot
3.1. Our Display
3.1.
Our Display
This cufflinks plot should display correctly.
3.2. Reference
3.2.
Reference