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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM