Home>
#-*-coding: utf-8-*-
import pandas as pd
Read #csv file
df = pd.read_csv ("./ test2.csv")
Extract only #datetime and id columns
df = df [["datetime", "id"]]
#Datatime numeric format can be calculated
df ["new"] = pd.to_datetime (df ["datetime"])
#Speed processing (second speed)
i = 0
a = 1
while i<= 8 and a<8:
If #id is the same, ask for speed per second
if df.iloc [i] [1] == df.iloc [a] [1]:
#When the minutes are the same, only the number of seconds is calculated
if df ["new"] [i] .minute == df ["new"] [a] .minute:
df ["speed"] = 50 // (df ["new"] [a] .second-df ["new"] [i] .second)
print (50 // (df ["new"] [a] .second-df ["new"] [i] .second))
#Calculate by changing minutes to seconds
else:
df ["speed"] = 50 // ((df ["new"] [a] .minute-df ["new"] [i] .minute) * 60 + (df ["new"] [a]. second-df ["new"] [i] .second))
#elif df.iloc [i] [1]! = df.iloc [a] [1]:
#df ["speed"] = "nothing"
i + = 1
a + = 1
#Check output format of csv file
print (df)
#Write csv file (write the value of speed per second to csv file)
df.to_csv ('test2.csv')
Question
I am working on writing csv files using python pandas. Is it possible to use pandas to enter different values for specific lines?
If possible, I would be grateful if you could tell me a specific method such as a reference site
, datetime, id
0,2019-02-21 17: 15: 14.500000,9
1,2019-02-21 17: 15: 15.700000,9
2,2019-02-21 17: 15: 33.300000,117
3,2019-02-21 17: 16: 11.600000,213
4,2019-02-21 17: 16: 12.700000,213
5,2019-02-21 17: 16: 12.700000,193
6,2019-02-21 17: 19: 10.300000,533
7,2019-02-21 17: 19: 11.400000,533
8,2019-02-21 17: 20: 14.800000,681
-
Answer # 1
-
Answer # 2
As it is, if you go around with "csv file python pandas", you will get a useful page
Related articles
- python - i want to modify the value of a specific column or row of pandas using the apply function and the lambda function
- python - unable to extract one value with pandas ilocvalues
- python - i want to display only a specific value axis on the horizontal axis in matplotlib
- substitute the value of a specific line of csv read into python
- python - i can't understand the specifications of pandas
- python 3x - how to get the value of scrolledtext
- python 3x - how to extract row and column numbers with specific values in a dataframe table
- i want to dynamically change the value of a variable in python and execute it
- python - updating a specific column in each row does not work in the case of duplicate index in dataframe
- python - yolo i want to detect only a specific class
- python - count by element with pivot_table in pandas
- python - about data analysis in pandas
- i want to set the maximum value of the slider in python to the number entered in the text box
- python - how to output the key and value in the dictionary in any form
- python - [pandas] how to search for unexpected data
- python 3x - i want to replace a specific sentence end expression with an arbitrary character string
- python - i want to separate by a specific word using the split function
- python pandas pivot_table is not reflected
- i want to get the value from a constant in python and display it
- put the maximum value of the list of variables in the objective function with python pulp
Related questions
- python : Dataframe -can't get the Date column
- python : How to conditionally replace values in a DataFrame column with values from another DataFrame
- python : Checking the uniqueness of records in a file
- python : How do I assemble a DataFrame?
- python : Remove all non-alphabetic characters from each cell in the column
- python : How to replace NaN values of a column in a dataframe with values from another dataframe by key?
- python : I want to convert the date format of CSV data
- python : I want to subtract each column of dataframe by the value of the first column
- python : Replacing double for-if loop with built-in functions in pandas
- python : 'DataFrame' object has no attribute on function call
I imagine that this is probably what I want to do, but how about it?
A major fix is
Add
index_col
andparse_dates
as parameters ofread_csv ()
when reading CSVYou don't have to bother to calculate the time difference every minute and every second, just subtract and get the seconds with
total_seconds ()
Assign a value to a specific cell of DataFrame with
df.loc [row index value, column name of column] = value
(The same is true for cell values)
However, with the above method, even if the ID value is the same, the speed is not calculated unless the rows are continuous, so
groupby ('id')
I think it ’s better to calculate