#Python 檔案讀取file.read(), file.readlines(), file.readline()
“””
read.txt內容:
Hello! World!
哈囉!世界!
1 2 3 4 5
with open( ) as file:
會自動關閉檔案
最末可以少打
file.close()
“””

“””
使用.readlines()
跟.read() 一樣
都是讀取全部的資料
差別是 .readlines()
\n的換列字元也會涵蓋
而且回傳一個list
“””

“””
file.readline()
只有讀取一行
“””

“””
read.txt內容:
Hello World
中文
1 2 3 4 5 6
“””
#使用以下方式去掉\n:






![Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()] Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()]](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2024/11/20241123194900_0_5218de.png?quality=90&zoom=2&ssl=1&resize=350%2C233)




近期留言