If you do not specify a column name, consecutive column names starting with 0 are automatically generated, so you can rewrite the value of the second column by specifying 1
in the column name.
sample code
import pandas as pd
from io import StringIO
US>"s=""
2022/01/01 0:30:00,250
2022/01/01 1:00:00,200
"""
df = pd.read_csv (StringIO(s), header = None)
df[1] = df[1] * 2 # Rewrite the second column
print(df)
Run Results
01
0 2022/01/01 0:30:00 500
1 2022/01/01 1:00:00 400
import pandas as pd
importio
csv_data='"
2022/1/1 0:30,250
2022/1/1 1:00,220
'''
df=pd.read_csv(io.StringIO(csv_data), header=None)
#
print(df)
df.iloc[:,1]*=2
print(df)
# 0 1
# 0 2022/1/1 0:30 250
# 1 2022/1/1 1:00 220
#
# 0 1
# 0 2022/1/1 0:30 500
# 1 2022/1/1 1:00 440
© 2024 OneMinuteCode. All rights reserved.