Skip to content

Instantly share code, notes, and snippets.

@seven0525
Last active May 24, 2018 02:51
Show Gist options
  • Save seven0525/f8eeef8ede55d8b00f2a19dcadae8292 to your computer and use it in GitHub Desktop.
Save seven0525/f8eeef8ede55d8b00f2a19dcadae8292 to your computer and use it in GitHub Desktop.
「自作Python100本ノック」10日目(63本〜70本目) ref: https://qiita.com/ahpjop/items/f92fe9fcd8f39cd44952
from datetime import date
now = date.today()
now_str = now.isoformat() #文字列の形にする
with open("today.txt", "wt") as outfile:
outfile.write(now_str)
now_str
import time
fmt = '%Y-%m-%d'
time.strptime(today_string, fmt)
# カレントディレクトリのファイルのリストを作ろう
import os
os.listdir('.')
# 親ディレクトリのファイルのリストを作ろう
os.listdir('..')
from datetime import date
my_time = date(1998, 5, 11)
my_time.weekday() #月曜が0、日曜が6
from datetime import timedelta
my_future = my_time + timedelta(days=10000)
my_future
df = pd.DataFrame(
{'名前': ['朝倉', '鈴木', '山中', '田中', '山本'],
'年齢': [17, 43, 40, 12, 62],
'性別':['男', '男', '女', '男', '女']})
df
df_1 = df[df['年齢'] < 35]
df_1
# 行の追加
row = pd.DataFrame({'名前': ['池田'],
'年齢': [1989],
'性別': '男'})
# 行の追加(行: axis=0, 列: axis=1)
df_2 = pd.concat([df,row], axis=0)
df_2
# indexを変更
# np.agrangeで0〜6の数字が並んだ配列を生成
df_2.index = np.arange(len(df_2))
df_2
# 列の追加
# 新たな列を代入
df_2['居住地'] = ['東京', '大阪', '北海道', '宮城', '富山', '大分']
df_2
# 列を削除(行: axis=0, 列: axis=1)
df_3 = df_2.drop('性別', axis=1)
df_3
df_4.columns = ['name', 'age', 'residence']
df_4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment