I have this data set which have 3 rows. 2nd column is date column which have date in two different format. How can i select date of particular format to display that particular row. i mean there are more rows which have different date format. how can i select all the rows with date format year/date/month and then after selecting all these rows of this format year/date/month and then change to that year/month/date format . Main problem in selecting of particular format
Country date
18 Australia 2020-01-18 0.0 0.0 0.0 0.0 44648.71 25499881.0 2020-03-24
19 Australia 2020-19-01 0.0 0.0 0.0 0.0 44648.71 25499881.0 2020-03-24
20 Australia 2020-01-20 0.0 0.0 0.0 0.0 44648.71 25499881.0 2020-03-24
You can try this option (not very elegant):
Dataset:
Country,date
Australia,2020-01-18
Australia,2020-19-01
Australia,2020-01-20
Code:
import pandas as pd
import numpy as np
df = pd.read_csv("file.csv")
df = df.astype('str')
df['date'] = np.where(df['date'].str[5:7].astype('int') > 12
, df['date'].str[0:4] + df['date'].str[7:11] + df['date'].str[4:7]
, df['date'])
print(df)
Output:
Country date
0 Australia 2020-01-18
1 Australia 2020-01-19
2 Australia 2020-01-20
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加