程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

In Python, a list is merged, the dataframe removes the specified characters, and the dataframe adds data line by line

編輯:Python

Recently written LeetCode Code encountered a few small knowledge points to sum up .

1. A list merges its own elements , It is different from two lists merging one list ( This just needs l1+l2 You can merge )

a = ['d','a','t','a']
k = 0
a_str = ' '
while k<len(a):
a_str = a_str + str(a[k])
k +=1
print(a_str)
# 'data'

2.dataframe Remove specified characters

# 'I like football\n' Get rid of \n, It can also be other characters
data['label'] = data['label'].apply(lambda x: x.replace("\n", ""))
# Output :I like football

3.dataframe Add data line by line

data = pd.DataFrame(columns=['api', 'label'])
# i It's the index , insert_data Is the data to be added to this row , use iloc It's fine too
data .at[i, 'api'] = insert_data


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved