#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Jul 1 12:05:42 2023 @author: richardson """ import pandas as pd import numpy as np import matplotlib.pyplot as plt # dataframes and histograms # new way to construct a dataframe # uses a "dictionary" df = pd.DataFrame( { 'S': np.random.randn(1000)*3+2, # mean =2, stdev=3 "T": np.random.randn(1000), # mean 0, stddev 1 "U": np.random.randn(1000)-4 # mean -4, stddev 1 }, columns = list('STU') ) #print(df.head()) #print(df.info()) #plt.figure() #df.plot.hist(bins=40 # ,alpha=0.5) #plt.show() df2 = pd.DataFrame(np.random.rand(50,4), columns=['a','b','c','d']) #df2.plot.scatter(x='a',y='b') #df2.plot.scatter(x='a',y='b',c='c',s=df2['d']*100) # making a series data frame df3 = pd.Series({1:1,4:8,9:27,16:64,17:17}) print(df3) bubba = [[1,2,3],[-2,3,-7],[4,4,4],[0,0,5]] cols = ['hi','there','yall'] df4 = pd.DataFrame(data=bubba,columns=cols) print(df4) #print(df4[2][1]) does not work print(df4.loc[2,'there']) print(df4.at[2,'there']) print(df4.iloc[[2],[1]]) print(df4.iat[2,1]) print(df4.loc[2]) #row with index 2 print(df4.loc[:,'there']) # column 'there'