我想在执行这个查询时插入一个列DBREMOVECMD
;
df1ac.insert(0, column = "DBREMOVECMD", value = ("delete analog19_1.tp_table where NE_ID = " + str(df1ac["NE_ID"]) + " ;"))
我希望从这个查询的输出中得到一列。
print(df1ac)
LASTCOLLPER LASTCOLLECTIONPERIOD TimestampY FARK NE_ID
0 19700101000000 0 1675227525 1675227525 4135862
1 19700101000000 0 1675227525 1675227525 4135863
2 19700101000000 0 1675227525 1675227525 4135825
3 19700101000000 0 1675227525 1675227525 4135824
df1ac.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4 entries, 0 to 3
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 LASTCOLLPER 4 non-null int64
1 LASTCOLLECTIONPERIOD 4 non-null int64
2 TimestampY 4 non-null int64
3 FARK 4 non-null int64
4 NE_ID 4 non-null int64
dtypes: int64(5)
memory usage: 288.0 bytes
df1ac.insert(0, column = "DBREMOVECMD", value = ("delete analog19_1.tp_table where NE_ID = " + str(df1ac["NE_ID"]) + " ;"))
print(df1ac)
DBREMOVECMD ... NE_ID
0 delete analog19_1.tp_table where NE_ID = 0 ... ... 4135862
1 delete analog19_1.tp_table where NE_ID = 0 ... ... 4135863
2 delete analog19_1.tp_table where NE_ID = 0 ... ... 4135825
3 delete analog19_1.tp_table where NE_ID = 0 ... ... 4135824
[4 rows x 6 columns]
df1ac.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4 entries, 0 to 3
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 DBREMOVECMD 4 non-null object
1 LASTCOLLPER 4 non-null int64
2 LASTCOLLECTIONPERIOD 4 non-null int64
3 TimestampY 4 non-null int64
4 FARK 4 non-null int64
5 NE_ID 4 non-null int64
dtypes: int64(5), object(1)
memory usage: 320.0+ bytes
print(df1ac.loc[0])
DBREMOVECMD delete analog19_1.tp_table where NE_ID = 0 ...
LASTCOLLPER 19700101000000
LASTCOLLECTIONPERIOD 0
TimestampY 1675227525
FARK 1675227525
NE_ID 4135862
Name: 0, dtype: object
print(df1ac.loc[0].DBREMOVECMD)
delete analog19_1.tp_table where NE_ID = 0 4135862
1 4135863
2 4135825
3 4135824
Name: NE_ID, dtype: int64 ;
print(df1ac.loc[1].DBREMOVECMD)
delete analog19_1.tp_table where NE_ID = 0 4135862
1 4135863
2 4135825
3 4135824
Name: NE_ID, dtype: int64 ;
1条答案
按热度按时间ibps3vxo1#
您的问题是使用
str(df1ac["NE_ID"])
,它将整个NE_ID
列转换为字符串,并将value
中只有一个值,然后将其插入到dataframe的 every 行中。相反,您应该使用df1ac["NE_ID"].astype(str)
来生成一系列值:输出: