Python Notes



Pandas


Convert From Dictionary to Pandas DataFrame
pandas.DataFrame(Dictionary.items())  # or list(df.iteritems()) in python 3
Out[11]:
             0    1
0   2012-07-02  392
1   2012-07-06  392
2   2012-06-29  391
3   2012-06-28  391

df = pandas.DataFrame(Dictionary.items(), columns=['Date', 'DateValue'])


Number of Row
len(df)


Types of Data by Column of a Pandas DF
df.dtypes


List Columns
df.columns


List first row
df.loc[1]


Histogram (simple)
# set up
import random 

import matplotlib.pyplot as plt
x = random.sample(range(1000), 100)

plt.hist(x, bins=50, color='blue')

Frequency Table
Be careful with continuous data
df["colName"].value_counts()

for lots of unique values (continuous data)
df["colName"].value_counts(sort = False, bins = 30)




Comments