# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import os
os.getcwd()

os.chdir('C:\\Users\\Admin\\Desktop\\')

os.getcwd()

import pandas as pd
import numpy as np

tips = pd.read_csv('tips.csv')

tips

a=input(int(x))

a

pd.read_csv('C:\\Users\\Admin\\Desktop\\tips.csv')

type(tips)

len(tips)

len(tips.columns)

tips.head(2)

tips.tail(6)

tips[['total_bill','sex','smoker','time']]

tips[tips['time']=='Dinner']

stats.to_json('stats.json')

tips[(tips['time']=='Dinner') & (tips['tip']>5)].tail()

len(tips[(tips['size']>5) | (tips['total_bill']>45)])

tips.groupby(['smoker','sex']).size()

tips.groupby(['smoker','day','sex']).agg({'tip':np.mean, 'size':np.sum})

df_male=tips[(tips['sex']=='Male')]

df_male.groupby(['smoker']).agg({'tip':np.mean})

dplyr

stats= pd.read_csv('DemographicData.csv')

len(stats)

len(stats.columns)

stats.info()

data=stats.describe()

data.to_csv('data.csv')

stats

stats.columns = ['CountryName', 'CountryCode','BirthRate','InternetUsers','IncomeGroup']

stats.rename(columns={'CN':'CountryName'}, inplace=True)

stats

stats[1:4][['CountryName','BirthRate']]

stats[stats['CountryName'].isin(['India','Pakistan'])]

stats['MyCalc'] = stats.BirthRate*stats.InternetUsers

stats

stats.sort_values(['MyCalc'], ascending=1)

stats.drop('MyCalc',axis=1,inplace=True)

stats

raw_data = {'c_id':[1,2,3], 'c_name':['a','b','c']}

raw_data1 = {'c_id':[4,5,6], 'c_name':['y','x','z']}

a=pd.DataFrame(raw_data)

b = pd.DataFrame(raw_data1)

a

b

pd.concat([a,b],axis=0)

stats[stats.InternetUsers<2]

stats.IncomeGroup.unique()

stats.drop(['InternetUsers','IncomeGroup'],axis=1)

stats

import seaborn as sns

sns.lmplot(data=stats, x='InternetUsers', y='BirthRate',fit_reg=False,hue='IncomeGroup')

stats[stats.InternetUsers<2]

df1 = pd.DataFrame(np.array([['a',5,10],['b',4,61], ['c',24,19]]), columns=['name','attr1','attr2'])

df1

df2 = pd.DataFrame(np.array([['a',5,19],['b',4,15], ['c',2,9]]), columns=['name','attr1','attr2'])

df2

df3 = pd.DataFrame(np.array([['a',5,20],['b',3,61], ['e',3,19]]), columns=['name','attr1','attr2'])

df1

df2

df3

pd.merge(pd.merge(df1, df2, on='name', how='right'), df3, on='name', how='right')

df1.merge(df2,on='name').merge(df3, on='name')

pd.merge(df1,df2, how='inner', left_on=['name','attr1'])

from dfply import *

flight_data = pd.read_csv('flight_data.csv')

flight_data

(flight_data >>
 select (X.origin, X.dest, X.hour))


(flight_data>>
drop(X.year, X.month, X.day))

(flight_data>>
select(~X.hour, ~X.minute))

(flight_data>>
mask(X.month==1, X.day==1, X.origin=='JFK', X.hour>10))

(flight_data>>
arrange(X.distance, X.hour,ascending=False))

(flight_data>>
mask(X.origin=='EWR')>>
mutate(new_distance=X.distance/1000,
      carrier_origin = X.carrier + X.origin))

(flight_data>>
group_by(X.origin))

(flight_data>>
group_by(X.origin)>>
summarise(mean_disctance=X.distance.min()))

(flight_data>>
 mask(X.hour>10)>>
mutate(speed = X.distance/(X.air_time*60))>>
group_by(X.origin)>>
summarise(mean_speed=X.speed.mean())>>
arrange(X.mean_speed, ascending=False))



StarcoderdataJupyterScriptsDedupFiltered