2019-04-18 Python Base 1

C:\Users\Jeffery1u>python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> 23+7
30
>>> 4**2
16
>>> result=20
>>> print(result)
20
>>> x=30
>>> x+=70
>>> x
100
>>> int(4.3)
4
>>> float(10)
10.0
>>> round(4.67)
5
>>> # i love u
... x=30
>>> x
30
>>> type(x)
<class 'int'>
>>> str='i love u'
>>> str
'i love u'
>>> # 使用双引号开始字符串,单引号开始内部字符串
... str="i love 'u'"
>>> str
"i love 'u'"
>>> print(str)
i love 'u'
>>> str='''i'm love "u" '''
>>> print(str)
i'm love "u"
>>> #上面也可以使用三引号
... #使用加号字符串
... pring("a"+"b")
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
NameError: name 'pring' is not defined
>>> print("a"+"b")
ab
>>> "a"+"b" 

  

# list=[1,2.0,'3.0']
# for i in list:
#     print(i)
# print(list[-1])
# print(list[0:])
# print(list[1:-1])

# list=[[1,2.0,'3.0'],[1,2.0,'3.0'],[1,2.0,'3.0']] #列表列表
#
# print(list[0][0])


from csv import reader
apps_data=list(reader(open('AppleStore.csv')))
print(apps_data[:5]) #前五行数据

row_1 = ['Facebook', 0.0, 'USD', 2974676, 3.5]
row_2 = ['Instagram', 0.0, 'USD', 2161558, 4.5]
row_3 = ['Clash of Clans', 0.0, 'USD', 2130805, 4.5]
row_4 = ['Temple Run', 0.0, 'USD', 1724546, 4.5]
row_5 = ['Pandora - Music & Radio', 0.0, 'USD', 1126879, 4.0]
rating_sum=0
app_data_set = [row_1, row_2, row_3, row_4, row_5]
# for rating in app_data_set:
#     rating_sum=rating[4]+rating_sum
# print(float(rating_sum/len(app_data_set))) #小数尽可能用浮点型

ratings=[]
for row in app_data_set:
    ratings.append(row[-1])
print(ratings)
avg_rating =sum(ratings)/len(ratings)
print(avg_rating)#列表求和 求个数

content_ratings = {'4+': 4433, '9+': 987, '12+': 1155, '17+': 622}
# dictionary_name[index] = value 修改 或 添加新值

#判断是否存在键
dic={}
list=[]
for l in list:
    if l in dic:
        dic[l]=1
    else:
        dic[l] = 1

#函数 返回值
def freq_table(index):
    frequency_table = {}

    for row in apps_data[1:]:
        value = row[index]
        if value in frequency_table:
            frequency_table[value] += 1
        else:
            frequency_table[value] = 1

    return frequency_table

  

转载于:https://www.cnblogs.com/theDataDigger/p/10728211.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值